OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrShaderVar_DEFINED | 8 #ifndef GrShaderVar_DEFINED |
9 #define GrShaderVar_DEFINED | 9 #define GrShaderVar_DEFINED |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 kOut_TypeModifier, | 27 kOut_TypeModifier, |
28 kIn_TypeModifier, | 28 kIn_TypeModifier, |
29 kInOut_TypeModifier, | 29 kInOut_TypeModifier, |
30 kUniform_TypeModifier, | 30 kUniform_TypeModifier, |
31 // GL Specific types below | 31 // GL Specific types below |
32 kAttribute_TypeModifier, | 32 kAttribute_TypeModifier, |
33 kVaryingIn_TypeModifier, | 33 kVaryingIn_TypeModifier, |
34 kVaryingOut_TypeModifier | 34 kVaryingOut_TypeModifier |
35 }; | 35 }; |
36 | 36 |
37 enum Precision { | |
38 kLow_Precision, | |
39 kMedium_Precision, | |
40 kHigh_Precision, | |
41 | |
42 // Default precision is medium. This is because on OpenGL ES 2 highp sup
port is not | |
43 // guaranteed. On (non-ES) OpenGL the specifiers have no effect on preci
sion. | |
44 kDefault_Precision = kMedium_Precision, | |
45 | |
46 kLast_Precision = kHigh_Precision | |
47 }; | |
48 static const int kPrecisionCount = kLast_Precision + 1; | |
49 | |
50 /** | 37 /** |
51 * Defaults to a float with no precision specifier | 38 * Defaults to a float with no precision specifier |
52 */ | 39 */ |
53 GrShaderVar() | 40 GrShaderVar() |
54 : fType(kFloat_GrSLType) | 41 : fType(kFloat_GrSLType) |
55 , fTypeModifier(kNone_TypeModifier) | 42 , fTypeModifier(kNone_TypeModifier) |
56 , fCount(kNonArray) | 43 , fCount(kNonArray) |
57 , fPrecision(kDefault_Precision) { | 44 , fPrecision(kDefault_GrSLPrecision) { |
58 } | 45 } |
59 | 46 |
60 GrShaderVar(const SkString& name, GrSLType type, int arrayCount = kNonArray, | 47 GrShaderVar(const SkString& name, GrSLType type, int arrayCount = kNonArray, |
61 Precision precision = kDefault_Precision) | 48 GrSLPrecision precision = kDefault_GrSLPrecision) |
62 : fType(type) | 49 : fType(type) |
63 , fTypeModifier(kNone_TypeModifier) | 50 , fTypeModifier(kNone_TypeModifier) |
64 , fName(name) | 51 , fName(name) |
65 , fCount(arrayCount) | 52 , fCount(arrayCount) |
66 , fPrecision(precision) { | 53 , fPrecision(precision) { |
67 SkASSERT(kVoid_GrSLType != type); | 54 SkASSERT(kVoid_GrSLType != type); |
68 } | 55 } |
69 | 56 |
70 GrShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray, | 57 GrShaderVar(const char* name, GrSLType type, int arrayCount = kNonArray, |
71 Precision precision = kDefault_Precision) | 58 GrSLPrecision precision = kDefault_GrSLPrecision) |
72 : fType(type) | 59 : fType(type) |
73 , fTypeModifier(kNone_TypeModifier) | 60 , fTypeModifier(kNone_TypeModifier) |
74 , fName(name) | 61 , fName(name) |
75 , fCount(arrayCount) | 62 , fCount(arrayCount) |
76 , fPrecision(precision) { | 63 , fPrecision(precision) { |
77 SkASSERT(kVoid_GrSLType != type); | 64 SkASSERT(kVoid_GrSLType != type); |
78 } | 65 } |
79 | 66 |
80 GrShaderVar(const char* name, GrSLType type, TypeModifier typeModifier, | 67 GrShaderVar(const char* name, GrSLType type, TypeModifier typeModifier, |
81 int arrayCount = kNonArray, Precision precision = kDefault_Pre
cision) | 68 int arrayCount = kNonArray, GrSLPrecision precision = kDefault
_GrSLPrecision) |
82 : fType(type) | 69 : fType(type) |
83 , fTypeModifier(typeModifier) | 70 , fTypeModifier(typeModifier) |
84 , fName(name) | 71 , fName(name) |
85 , fCount(arrayCount) | 72 , fCount(arrayCount) |
86 , fPrecision(precision) { | 73 , fPrecision(precision) { |
87 SkASSERT(kVoid_GrSLType != type); | 74 SkASSERT(kVoid_GrSLType != type); |
88 } | 75 } |
89 | 76 |
90 /** | 77 /** |
91 * Values for array count that have special meaning. We allow 1-sized arrays
. | 78 * Values for array count that have special meaning. We allow 1-sized arrays
. |
92 */ | 79 */ |
93 enum { | 80 enum { |
94 kNonArray = 0, // not an array | 81 kNonArray = 0, // not an array |
95 kUnsizedArray = -1, // an unsized array (declared with []) | 82 kUnsizedArray = -1, // an unsized array (declared with []) |
96 }; | 83 }; |
97 | 84 |
98 /** | 85 /** |
99 * Sets as a non-array. | 86 * Sets as a non-array. |
100 */ | 87 */ |
101 void set(GrSLType type, | 88 void set(GrSLType type, |
102 TypeModifier typeModifier, | 89 TypeModifier typeModifier, |
103 const SkString& name, | 90 const SkString& name, |
104 Precision precision = kDefault_Precision) { | 91 GrSLPrecision precision = kDefault_GrSLPrecision) { |
105 SkASSERT(kVoid_GrSLType != type); | 92 SkASSERT(kVoid_GrSLType != type); |
106 fType = type; | 93 fType = type; |
107 fTypeModifier = typeModifier; | 94 fTypeModifier = typeModifier; |
108 fName = name; | 95 fName = name; |
109 fCount = kNonArray; | 96 fCount = kNonArray; |
110 fPrecision = precision; | 97 fPrecision = precision; |
111 } | 98 } |
112 | 99 |
113 /** | 100 /** |
114 * Sets as a non-array. | 101 * Sets as a non-array. |
115 */ | 102 */ |
116 void set(GrSLType type, | 103 void set(GrSLType type, |
117 TypeModifier typeModifier, | 104 TypeModifier typeModifier, |
118 const char* name, | 105 const char* name, |
119 Precision precision = kDefault_Precision) { | 106 GrSLPrecision precision = kDefault_GrSLPrecision) { |
120 SkASSERT(kVoid_GrSLType != type); | 107 SkASSERT(kVoid_GrSLType != type); |
121 fType = type; | 108 fType = type; |
122 fTypeModifier = typeModifier; | 109 fTypeModifier = typeModifier; |
123 fName = name; | 110 fName = name; |
124 fCount = kNonArray; | 111 fCount = kNonArray; |
125 fPrecision = precision; | 112 fPrecision = precision; |
126 } | 113 } |
127 | 114 |
128 /** | 115 /** |
129 * Set all var options | 116 * Set all var options |
130 */ | 117 */ |
131 void set(GrSLType type, | 118 void set(GrSLType type, |
132 TypeModifier typeModifier, | 119 TypeModifier typeModifier, |
133 const SkString& name, | 120 const SkString& name, |
134 int count, | 121 int count, |
135 Precision precision = kDefault_Precision) { | 122 GrSLPrecision precision = kDefault_GrSLPrecision) { |
136 SkASSERT(kVoid_GrSLType != type); | 123 SkASSERT(kVoid_GrSLType != type); |
137 fType = type; | 124 fType = type; |
138 fTypeModifier = typeModifier; | 125 fTypeModifier = typeModifier; |
139 fName = name; | 126 fName = name; |
140 fCount = count; | 127 fCount = count; |
141 fPrecision = precision; | 128 fPrecision = precision; |
142 } | 129 } |
143 | 130 |
144 /** | 131 /** |
145 * Set all var options | 132 * Set all var options |
146 */ | 133 */ |
147 void set(GrSLType type, | 134 void set(GrSLType type, |
148 TypeModifier typeModifier, | 135 TypeModifier typeModifier, |
149 const char* name, | 136 const char* name, |
150 int count, | 137 int count, |
151 Precision precision = kDefault_Precision) { | 138 GrSLPrecision precision = kDefault_GrSLPrecision) { |
152 SkASSERT(kVoid_GrSLType != type); | 139 SkASSERT(kVoid_GrSLType != type); |
153 fType = type; | 140 fType = type; |
154 fTypeModifier = typeModifier; | 141 fTypeModifier = typeModifier; |
155 fName = name; | 142 fName = name; |
156 fCount = count; | 143 fCount = count; |
157 fPrecision = precision; | 144 fPrecision = precision; |
158 } | 145 } |
159 | 146 |
160 /** | 147 /** |
161 * Is the var an array. | 148 * Is the var an array. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 * Set the type of the var | 197 * Set the type of the var |
211 */ | 198 */ |
212 void setType(GrSLType type) { fType = type; } | 199 void setType(GrSLType type) { fType = type; } |
213 | 200 |
214 TypeModifier getTypeModifier() const { return fTypeModifier; } | 201 TypeModifier getTypeModifier() const { return fTypeModifier; } |
215 void setTypeModifier(TypeModifier type) { fTypeModifier = type; } | 202 void setTypeModifier(TypeModifier type) { fTypeModifier = type; } |
216 | 203 |
217 /** | 204 /** |
218 * Get the precision of the var | 205 * Get the precision of the var |
219 */ | 206 */ |
220 Precision getPrecision() const { return fPrecision; } | 207 GrSLPrecision getPrecision() const { return fPrecision; } |
221 | 208 |
222 /** | 209 /** |
223 * Set the precision of the var | 210 * Set the precision of the var |
224 */ | 211 */ |
225 void setPrecision(Precision p) { fPrecision = p; } | 212 void setPrecision(GrSLPrecision p) { fPrecision = p; } |
226 | 213 |
227 protected: | 214 protected: |
228 GrSLType fType; | 215 GrSLType fType; |
229 TypeModifier fTypeModifier; | 216 TypeModifier fTypeModifier; |
230 SkString fName; | 217 SkString fName; |
231 int fCount; | 218 int fCount; |
232 Precision fPrecision; | 219 GrSLPrecision fPrecision; |
233 }; | 220 }; |
234 | 221 |
235 #endif | 222 #endif |
OLD | NEW |