| 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 | |
| robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | #include "GrGLContext.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, |
| bsalomon@google.com | 77cf460 | 2013-04-22 21:05:48 +0000 | [diff] [blame^] | 32 | kInOut_TypeModifier, |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 33 | kUniform_TypeModifier, |
| bsalomon@google.com | 77cf460 | 2013-04-22 21:05:48 +0000 | [diff] [blame^] | 34 | kAttribute_TypeModifier, |
| 35 | kVaryingIn_TypeModifier, |
| 36 | kVaryingOut_TypeModifier |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 39 | enum Precision { |
| 40 | kLow_Precision, // lowp |
| 41 | kMedium_Precision, // mediump |
| 42 | kHigh_Precision, // highp |
| 43 | kDefault_Precision, // Default for the current context. We make |
| 44 | // fragment shaders default to mediump on ES2 |
| 45 | // because highp support is not guaranteed (and |
| 46 | // we haven't been motivated to test for it). |
| 47 | // Otherwise, highp. |
| 48 | }; |
| 49 | |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 50 | /** |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 51 | * See GL_ARB_fragment_coord_conventions. |
| 52 | */ |
| 53 | enum Origin { |
| 54 | kDefault_Origin, // when set to kDefault the origin field is ignored. |
| 55 | kUpperLeft_Origin, // only used to declare vec4 in gl_FragCoord. |
| 56 | }; |
| 57 | |
| 58 | /** |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 59 | * Defaults to a float with no precision specifier |
| 60 | */ |
| 61 | GrGLShaderVar() { |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 62 | fType = kFloat_GrSLType; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 63 | fTypeModifier = kNone_TypeModifier; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 64 | fCount = kNonArray; |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 65 | fPrecision = kDefault_Precision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 66 | fOrigin = kDefault_Origin; |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 67 | fUseUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 70 | GrGLShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray) { |
| 71 | GrAssert(kVoid_GrSLType != type); |
| 72 | fType = type; |
| 73 | fTypeModifier = kNone_TypeModifier; |
| 74 | fCount = arrayCount; |
| 75 | fPrecision = kDefault_Precision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 76 | fOrigin = kDefault_Origin; |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 77 | fUseUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS; |
| 78 | fName = name; |
| 79 | } |
| 80 | |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 81 | GrGLShaderVar(const GrGLShaderVar& var) |
| 82 | : fType(var.fType) |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 83 | , fTypeModifier(var.fTypeModifier) |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 84 | , fName(var.fName) |
| 85 | , fCount(var.fCount) |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 86 | , fPrecision(var.fPrecision) |
| bsalomon@google.com | b7f9a86 | 2012-10-25 19:35:05 +0000 | [diff] [blame] | 87 | , fOrigin(var.fOrigin) |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 88 | , fUseUniformFloatArrays(var.fUseUniformFloatArrays) { |
| 89 | GrAssert(kVoid_GrSLType != var.fType); |
| 90 | } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Values for array count that have special meaning. We allow 1-sized arrays. |
| 94 | */ |
| 95 | enum { |
| 96 | kNonArray = 0, // not an array |
| 97 | kUnsizedArray = -1, // an unsized array (declared with []) |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * Sets as a non-array. |
| 102 | */ |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 103 | void set(GrSLType type, |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 104 | TypeModifier typeModifier, |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 105 | const SkString& name, |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 106 | Precision precision = kDefault_Precision, |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 107 | Origin origin = kDefault_Origin, |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 108 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 109 | GrAssert(kVoid_GrSLType != type); |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 110 | fType = type; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 111 | fTypeModifier = typeModifier; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 112 | fName = name; |
| 113 | fCount = kNonArray; |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 114 | fPrecision = precision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 115 | fOrigin = origin; |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 116 | fUseUniformFloatArrays = useUniformFloatArrays; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Sets as a non-array. |
| 121 | */ |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 122 | void set(GrSLType type, |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 123 | TypeModifier typeModifier, |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 124 | const char* name, |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 125 | Precision precision = kDefault_Precision, |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 126 | Origin origin = kDefault_Origin, |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 127 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 128 | GrAssert(kVoid_GrSLType != type); |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 129 | fType = type; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 130 | fTypeModifier = typeModifier; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 131 | fName = name; |
| 132 | fCount = kNonArray; |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 133 | fPrecision = precision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 134 | fOrigin = origin; |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 135 | fUseUniformFloatArrays = useUniformFloatArrays; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Set all var options |
| 140 | */ |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 141 | void set(GrSLType type, |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 142 | TypeModifier typeModifier, |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 143 | const SkString& name, |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 144 | int count, |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 145 | Precision precision = kDefault_Precision, |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 146 | Origin origin = kDefault_Origin, |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 147 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 148 | GrAssert(kVoid_GrSLType != type); |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 149 | fType = type; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 150 | fTypeModifier = typeModifier; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 151 | fName = name; |
| 152 | fCount = count; |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 153 | fPrecision = precision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 154 | fOrigin = origin; |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 155 | fUseUniformFloatArrays = useUniformFloatArrays; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Set all var options |
| 160 | */ |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 161 | void set(GrSLType type, |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 162 | TypeModifier typeModifier, |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 163 | const char* name, |
| 164 | int count, |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 165 | Precision precision = kDefault_Precision, |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 166 | Origin origin = kDefault_Origin, |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 167 | bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) { |
| bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 168 | GrAssert(kVoid_GrSLType != type); |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 169 | fType = type; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 170 | fTypeModifier = typeModifier; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 171 | fName = name; |
| 172 | fCount = count; |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 173 | fPrecision = precision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 174 | fOrigin = origin; |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 175 | fUseUniformFloatArrays = useUniformFloatArrays; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Is the var an array. |
| 180 | */ |
| 181 | bool isArray() const { return kNonArray != fCount; } |
| 182 | /** |
| 183 | * Is this an unsized array, (i.e. declared with []). |
| 184 | */ |
| 185 | bool isUnsizedArray() const { return kUnsizedArray == fCount; } |
| 186 | /** |
| 187 | * Get the array length of the var. |
| 188 | */ |
| 189 | int getArrayCount() const { return fCount; } |
| 190 | /** |
| 191 | * Set the array length of the var |
| 192 | */ |
| 193 | void setArrayCount(int count) { fCount = count; } |
| 194 | /** |
| 195 | * Set to be a non-array. |
| 196 | */ |
| 197 | void setNonArray() { fCount = kNonArray; } |
| 198 | /** |
| 199 | * Set to be an unsized array. |
| 200 | */ |
| 201 | void setUnsizedArray() { fCount = kUnsizedArray; } |
| 202 | |
| 203 | /** |
| 204 | * Access the var name as a writable string |
| 205 | */ |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 206 | SkString* accessName() { return &fName; } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 207 | /** |
| 208 | * Set the var name |
| 209 | */ |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 210 | void setName(const SkString& n) { fName = n; } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 211 | void setName(const char* n) { fName = n; } |
| bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 212 | |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 213 | /** |
| 214 | * Get the var name. |
| 215 | */ |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 216 | const SkString& getName() const { return fName; } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 217 | |
| 218 | /** |
| bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 219 | * Shortcut for this->getName().c_str(); |
| 220 | */ |
| 221 | const char* c_str() const { return this->getName().c_str(); } |
| 222 | |
| 223 | /** |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 224 | * Get the type of the var |
| 225 | */ |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 226 | GrSLType getType() const { return fType; } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 227 | /** |
| 228 | * Set the type of the var |
| 229 | */ |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 230 | void setType(GrSLType type) { fType = type; } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 231 | |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 232 | TypeModifier getTypeModifier() const { return fTypeModifier; } |
| 233 | void setTypeModifier(TypeModifier type) { fTypeModifier = type; } |
| 234 | |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 235 | /** |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 236 | * Get the precision of the var |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 237 | */ |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 238 | Precision getPrecision() const { return fPrecision; } |
| 239 | |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 240 | /** |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 241 | * Set the precision of the var |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 242 | */ |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 243 | void setPrecision(Precision p) { fPrecision = p; } |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 244 | |
| 245 | /** |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 246 | * Get the origin of the var |
| 247 | */ |
| 248 | Origin getOrigin() const { return fOrigin; } |
| 249 | |
| 250 | /** |
| 251 | * Set the origin of the var |
| 252 | */ |
| 253 | void setOrigin(Origin origin) { fOrigin = origin; } |
| 254 | |
| 255 | /** |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 256 | * Write a declaration of this variable to out. |
| 257 | */ |
| robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 258 | void appendDecl(const GrGLContextInfo& ctxInfo, SkString* out) const { |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 259 | if (kUpperLeft_Origin == fOrigin) { |
| 260 | // this is the only place where we specify a layout modifier. If we use other layout |
| 261 | // modifiers in the future then they should be placed in a list. |
| 262 | out->append("layout(origin_upper_left) "); |
| 263 | } |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 264 | if (this->getTypeModifier() != kNone_TypeModifier) { |
| bsalomon@google.com | 9639994 | 2012-02-13 14:39:16 +0000 | [diff] [blame] | 265 | out->append(TypeModifierString(this->getTypeModifier(), |
| robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 266 | ctxInfo.glslGeneration())); |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 267 | out->append(" "); |
| 268 | } |
| robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 269 | out->append(PrecisionString(fPrecision, ctxInfo.binding())); |
| tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 270 | GrSLType effectiveType = this->getType(); |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 271 | if (this->isArray()) { |
| 272 | if (this->isUnsizedArray()) { |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 273 | out->appendf("%s %s[]", |
| bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 274 | GrGLSLTypeString(effectiveType), |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 275 | this->getName().c_str()); |
| 276 | } else { |
| 277 | GrAssert(this->getArrayCount() > 0); |
| rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 278 | out->appendf("%s %s[%d]", |
| bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 279 | GrGLSLTypeString(effectiveType), |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 280 | this->getName().c_str(), |
| 281 | this->getArrayCount()); |
| 282 | } |
| 283 | } else { |
| 284 | out->appendf("%s %s", |
| bsalomon@google.com | 018f179 | 2013-04-18 19:36:09 +0000 | [diff] [blame] | 285 | GrGLSLTypeString(effectiveType), |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 286 | this->getName().c_str()); |
| 287 | } |
| 288 | } |
| 289 | |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 290 | void appendArrayAccess(int index, SkString* out) const { |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 291 | out->appendf("%s[%d]%s", |
| 292 | this->getName().c_str(), |
| 293 | index, |
| 294 | fUseUniformFloatArrays ? "" : ".x"); |
| 295 | } |
| 296 | |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 297 | void appendArrayAccess(const char* indexName, SkString* out) const { |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 298 | out->appendf("%s[%s]%s", |
| 299 | this->getName().c_str(), |
| 300 | indexName, |
| 301 | fUseUniformFloatArrays ? "" : ".x"); |
| 302 | } |
| 303 | |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 304 | private: |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 305 | static const char* TypeModifierString(TypeModifier t, GrGLSLGeneration gen) { |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 306 | switch (t) { |
| 307 | case kNone_TypeModifier: |
| 308 | return ""; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 309 | case kIn_TypeModifier: |
| bsalomon@google.com | 77cf460 | 2013-04-22 21:05:48 +0000 | [diff] [blame^] | 310 | return "in"; |
| 311 | case kInOut_TypeModifier: |
| 312 | return "inout"; |
| 313 | case kOut_TypeModifier: |
| 314 | return "out"; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 315 | case kUniform_TypeModifier: |
| 316 | return "uniform"; |
| 317 | case kAttribute_TypeModifier: |
| bsalomon@google.com | e55fd0f | 2012-02-10 15:56:06 +0000 | [diff] [blame] | 318 | return k110_GrGLSLGeneration == gen ? "attribute" : "in"; |
| bsalomon@google.com | 77cf460 | 2013-04-22 21:05:48 +0000 | [diff] [blame^] | 319 | case kVaryingIn_TypeModifier: |
| 320 | return k110_GrGLSLGeneration == gen ? "varying" : "in"; |
| 321 | case kVaryingOut_TypeModifier: |
| 322 | return k110_GrGLSLGeneration == gen ? "varying" : "out"; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 323 | default: |
| 324 | GrCrash("Unknown shader variable type modifier."); |
| 325 | return ""; // suppress warning |
| 326 | } |
| 327 | } |
| 328 | |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 329 | static const char* PrecisionString(Precision p, GrGLBinding binding) { |
| 330 | // Desktop GLSL has added precision qualifiers but they don't do anything. |
| 331 | if (kES2_GrGLBinding == binding) { |
| 332 | switch (p) { |
| 333 | case kLow_Precision: |
| 334 | return "lowp "; |
| 335 | case kMedium_Precision: |
| 336 | return "mediump "; |
| 337 | case kHigh_Precision: |
| 338 | return "highp "; |
| 339 | case kDefault_Precision: |
| 340 | return ""; |
| 341 | default: |
| 342 | GrCrash("Unexpected precision type."); |
| 343 | } |
| 344 | } |
| 345 | return ""; |
| 346 | } |
| 347 | |
| 348 | GrSLType fType; |
| tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 349 | TypeModifier fTypeModifier; |
| bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 350 | SkString fName; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 351 | int fCount; |
| bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 352 | Precision fPrecision; |
| bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 353 | Origin fOrigin; |
| tomhudson@google.com | da66898 | 2011-12-07 15:06:29 +0000 | [diff] [blame] | 354 | /// Work around driver bugs on some hardware that don't correctly |
| 355 | /// support uniform float [] |
| 356 | bool fUseUniformFloatArrays; |
| bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | #endif |