Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 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 GrShaderVar_DEFINED | |
| 9 #define GrShaderVar_DEFINED | |
| 10 | |
| 11 #include "GrTypesPriv.h" | |
| 12 #include "SkString.h" | |
| 13 | |
| 14 class GrShaderVar { | |
| 15 public: | |
| 16 /** | |
| 17 * Early versions of GLSL have Varying and Attribute; those are later | |
| 18 * deprecated, but we still need to know whether a Varying variable | |
|
bsalomon
2014/09/08 13:47:52
Should this and precision go into the GL class?
| |
| 19 * should be treated as In or Out. | |
| 20 */ | |
| 21 enum TypeModifier { | |
| 22 kNone_TypeModifier, | |
| 23 kOut_TypeModifier, | |
| 24 kIn_TypeModifier, | |
| 25 kInOut_TypeModifier, | |
| 26 kUniform_TypeModifier, | |
| 27 kAttribute_TypeModifier, | |
| 28 kVaryingIn_TypeModifier, | |
| 29 kVaryingOut_TypeModifier | |
| 30 }; | |
| 31 | |
| 32 enum Precision { | |
| 33 kLow_Precision, // lowp | |
| 34 kMedium_Precision, // mediump | |
| 35 kHigh_Precision, // highp | |
| 36 kDefault_Precision, // Default for the current context. We make | |
| 37 // fragment shaders default to mediump on ES2 | |
| 38 // because highp support is not guaranteed (and | |
| 39 // we haven't been motivated to test for it). | |
| 40 // Otherwise, highp. | |
| 41 }; | |
| 42 | |
| 43 /** | |
| 44 * Defaults to a float with no precision specifier | |
| 45 */ | |
| 46 GrShaderVar() | |
| 47 : fType(kFloat_GrSLType) | |
| 48 , fTypeModifier(kNone_TypeModifier) | |
| 49 , fCount(kNonArray) | |
| 50 , fPrecision(kDefault_Precision) { | |
| 51 } | |
| 52 | |
| 53 GrShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray, | |
| 54 Precision precision = kDefault_Precision) | |
| 55 : fType(type) | |
| 56 , fTypeModifier(kNone_TypeModifier) | |
| 57 , fName(name) | |
| 58 , fCount(arrayCount) | |
| 59 , fPrecision(precision) { | |
| 60 SkASSERT(kVoid_GrSLType != type); | |
| 61 } | |
| 62 | |
| 63 GrShaderVar(const char* name, GrSLType type, TypeModifier typeModifier, | |
| 64 int arrayCount = kNonArray, Precision precision = kDefault_Pre cision) | |
| 65 : fType(type) | |
| 66 , fTypeModifier(typeModifier) | |
| 67 , fName(name) | |
| 68 , fCount(arrayCount) | |
| 69 , fPrecision(precision) { | |
| 70 SkASSERT(kVoid_GrSLType != type); | |
| 71 } | |
| 72 | |
| 73 /** | |
| 74 * Values for array count that have special meaning. We allow 1-sized arrays . | |
| 75 */ | |
| 76 enum { | |
| 77 kNonArray = 0, // not an array | |
| 78 kUnsizedArray = -1, // an unsized array (declared with []) | |
| 79 }; | |
| 80 | |
| 81 /** | |
| 82 * Sets as a non-array. | |
| 83 */ | |
| 84 void set(GrSLType type, | |
| 85 TypeModifier typeModifier, | |
| 86 const SkString& name, | |
| 87 Precision precision = kDefault_Precision) { | |
| 88 SkASSERT(kVoid_GrSLType != type); | |
| 89 fType = type; | |
| 90 fTypeModifier = typeModifier; | |
| 91 fName = name; | |
| 92 fCount = kNonArray; | |
| 93 fPrecision = precision; | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * Sets as a non-array. | |
| 98 */ | |
| 99 void set(GrSLType type, | |
| 100 TypeModifier typeModifier, | |
| 101 const char* name, | |
| 102 Precision precision = kDefault_Precision) { | |
| 103 SkASSERT(kVoid_GrSLType != type); | |
| 104 fType = type; | |
| 105 fTypeModifier = typeModifier; | |
| 106 fName = name; | |
| 107 fCount = kNonArray; | |
| 108 fPrecision = precision; | |
| 109 } | |
| 110 | |
| 111 /** | |
| 112 * Set all var options | |
| 113 */ | |
| 114 void set(GrSLType type, | |
| 115 TypeModifier typeModifier, | |
| 116 const SkString& name, | |
| 117 int count, | |
| 118 Precision precision = kDefault_Precision) { | |
| 119 SkASSERT(kVoid_GrSLType != type); | |
| 120 fType = type; | |
| 121 fTypeModifier = typeModifier; | |
| 122 fName = name; | |
| 123 fCount = count; | |
| 124 fPrecision = precision; | |
| 125 } | |
| 126 | |
| 127 /** | |
| 128 * Set all var options | |
| 129 */ | |
| 130 void set(GrSLType type, | |
| 131 TypeModifier typeModifier, | |
| 132 const char* name, | |
| 133 int count, | |
| 134 Precision precision = kDefault_Precision) { | |
| 135 SkASSERT(kVoid_GrSLType != type); | |
| 136 fType = type; | |
| 137 fTypeModifier = typeModifier; | |
| 138 fName = name; | |
| 139 fCount = count; | |
| 140 fPrecision = precision; | |
| 141 } | |
| 142 | |
| 143 /** | |
| 144 * Is the var an array. | |
| 145 */ | |
| 146 bool isArray() const { return kNonArray != fCount; } | |
| 147 /** | |
| 148 * Is this an unsized array, (i.e. declared with []). | |
| 149 */ | |
| 150 bool isUnsizedArray() const { return kUnsizedArray == fCount; } | |
| 151 /** | |
| 152 * Get the array length of the var. | |
| 153 */ | |
| 154 int getArrayCount() const { return fCount; } | |
| 155 /** | |
| 156 * Set the array length of the var | |
| 157 */ | |
| 158 void setArrayCount(int count) { fCount = count; } | |
| 159 /** | |
| 160 * Set to be a non-array. | |
| 161 */ | |
| 162 void setNonArray() { fCount = kNonArray; } | |
| 163 /** | |
| 164 * Set to be an unsized array. | |
| 165 */ | |
| 166 void setUnsizedArray() { fCount = kUnsizedArray; } | |
| 167 | |
| 168 /** | |
| 169 * Access the var name as a writable string | |
| 170 */ | |
| 171 SkString* accessName() { return &fName; } | |
| 172 /** | |
| 173 * Set the var name | |
| 174 */ | |
| 175 void setName(const SkString& n) { fName = n; } | |
| 176 void setName(const char* n) { fName = n; } | |
| 177 | |
| 178 /** | |
| 179 * Get the var name. | |
| 180 */ | |
| 181 const SkString& getName() const { return fName; } | |
| 182 | |
| 183 /** | |
| 184 * Shortcut for this->getName().c_str(); | |
| 185 */ | |
| 186 const char* c_str() const { return this->getName().c_str(); } | |
| 187 | |
| 188 /** | |
| 189 * Get the type of the var | |
| 190 */ | |
| 191 GrSLType getType() const { return fType; } | |
| 192 /** | |
| 193 * Set the type of the var | |
| 194 */ | |
| 195 void setType(GrSLType type) { fType = type; } | |
| 196 | |
| 197 TypeModifier getTypeModifier() const { return fTypeModifier; } | |
| 198 void setTypeModifier(TypeModifier type) { fTypeModifier = type; } | |
| 199 | |
| 200 /** | |
| 201 * Get the precision of the var | |
| 202 */ | |
| 203 Precision getPrecision() const { return fPrecision; } | |
| 204 | |
| 205 /** | |
| 206 * Set the precision of the var | |
| 207 */ | |
| 208 void setPrecision(Precision p) { fPrecision = p; } | |
| 209 | |
| 210 protected: | |
| 211 GrSLType fType; | |
| 212 TypeModifier fTypeModifier; | |
| 213 SkString fName; | |
| 214 int fCount; | |
| 215 Precision fPrecision; | |
| 216 }; | |
| 217 | |
| 218 #endif | |
| OLD | NEW |