OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrTypesPriv_DEFINED | 8 #ifndef GrTypesPriv_DEFINED |
9 #define GrTypesPriv_DEFINED | 9 #define GrTypesPriv_DEFINED |
10 | 10 |
11 #include "GrTypes.h" | 11 #include "GrTypes.h" |
12 #include "SkRect.h" | 12 #include "SkRect.h" |
13 | 13 |
14 /** | 14 /** |
15 * Types of shader-language-specific boxed variables we can create. (Currently
only GrGLShaderVars, | 15 * Types of shader-language-specific boxed variables we can create. (Currently
only GrGLShaderVars, |
16 * but should be applicable to other shader languages.) | 16 * but should be applicable to other shader languages.) |
17 */ | 17 */ |
18 enum GrSLType { | 18 enum GrSLType { |
19 kVoid_GrSLType, | 19 kVoid_GrSLType, |
20 kFloat_GrSLType, | 20 kFloat_GrSLType, |
21 kVec2f_GrSLType, | 21 kVec2f_GrSLType, |
22 kVec3f_GrSLType, | 22 kVec3f_GrSLType, |
23 kVec4f_GrSLType, | 23 kVec4f_GrSLType, |
24 kMat22f_GrSLType, | 24 kMat22f_GrSLType, |
25 kMat33f_GrSLType, | 25 kMat33f_GrSLType, |
26 kMat44f_GrSLType, | 26 kMat44f_GrSLType, |
27 kSampler2D_GrSLType, | 27 kSampler2D_GrSLType, |
28 kSamplerExternal_GrSLType, | 28 kSamplerExternal_GrSLType, |
29 kSampler2DRect_GrSLType, | 29 kSampler2DRect_GrSLType, |
| 30 kSamplerBuffer_GrSLType, |
30 kBool_GrSLType, | 31 kBool_GrSLType, |
31 kInt_GrSLType, | 32 kInt_GrSLType, |
32 kUint_GrSLType, | 33 kUint_GrSLType, |
33 | 34 |
34 kLast_GrSLType = kUint_GrSLType | 35 kLast_GrSLType = kUint_GrSLType |
35 }; | 36 }; |
36 static const int kGrSLTypeCount = kLast_GrSLType + 1; | 37 static const int kGrSLTypeCount = kLast_GrSLType + 1; |
37 | 38 |
38 enum GrShaderType { | 39 enum GrShaderType { |
39 kVertex_GrShaderType, | 40 kVertex_GrShaderType, |
(...skipping 29 matching lines...) Expand all Loading... |
69 kLast_GrSLPrecision = kHigh_GrSLPrecision | 70 kLast_GrSLPrecision = kHigh_GrSLPrecision |
70 }; | 71 }; |
71 | 72 |
72 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; | 73 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; |
73 | 74 |
74 /** | 75 /** |
75 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. | 76 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. |
76 */ | 77 */ |
77 static inline int GrSLTypeVectorCount(GrSLType type) { | 78 static inline int GrSLTypeVectorCount(GrSLType type) { |
78 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 79 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
79 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, 1, 1,
1 }; | 80 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1, 1
, 1, 1 }; |
80 return kCounts[type]; | 81 return kCounts[type]; |
81 | 82 |
82 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 83 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
83 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 84 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
84 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 85 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
85 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 86 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
86 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 87 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
87 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); | 88 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); |
88 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); | 89 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); |
89 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); | 90 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); |
90 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 91 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); |
91 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 92 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); |
92 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 93 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
93 GR_STATIC_ASSERT(11 == kBool_GrSLType); | 94 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); |
94 GR_STATIC_ASSERT(12 == kInt_GrSLType); | 95 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
95 GR_STATIC_ASSERT(13 == kUint_GrSLType); | 96 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
| 97 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
96 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); | 98 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
97 } | 99 } |
98 | 100 |
99 /** Return the type enum for a vector of floats of length n (1..4), | 101 /** Return the type enum for a vector of floats of length n (1..4), |
100 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ | 102 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
101 static inline GrSLType GrSLFloatVectorType(int count) { | 103 static inline GrSLType GrSLFloatVectorType(int count) { |
102 SkASSERT(count > 0 && count <= 4); | 104 SkASSERT(count > 0 && count <= 4); |
103 return (GrSLType)(count); | 105 return (GrSLType)(count); |
104 | 106 |
105 GR_STATIC_ASSERT(kFloat_GrSLType == 1); | 107 GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
(...skipping 11 matching lines...) Expand all Loading... |
117 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 119 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
118 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 120 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
119 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 121 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
120 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 122 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
121 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); | 123 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); |
122 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); | 124 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); |
123 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); | 125 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); |
124 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 126 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); |
125 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 127 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); |
126 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 128 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
127 GR_STATIC_ASSERT(11 == kBool_GrSLType); | 129 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); |
128 GR_STATIC_ASSERT(12 == kInt_GrSLType); | 130 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
129 GR_STATIC_ASSERT(13 == kUint_GrSLType); | 131 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
130 GR_STATIC_ASSERT(14 == kGrSLTypeCount); | 132 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
| 133 GR_STATIC_ASSERT(15 == kGrSLTypeCount); |
131 } | 134 } |
132 | 135 |
133 /** Is the shading language type integral (including vectors/matrices)? */ | 136 /** Is the shading language type integral (including vectors/matrices)? */ |
134 static inline bool GrSLTypeIsIntType(GrSLType type) { | 137 static inline bool GrSLTypeIsIntType(GrSLType type) { |
135 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 138 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
136 return type >= kInt_GrSLType; | 139 return type >= kInt_GrSLType; |
137 | 140 |
138 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 141 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
139 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 142 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
140 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 143 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
141 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 144 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
142 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 145 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
143 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); | 146 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); |
144 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); | 147 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); |
145 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); | 148 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); |
146 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 149 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); |
147 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 150 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); |
148 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 151 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
149 GR_STATIC_ASSERT(11 == kBool_GrSLType); | 152 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); |
150 GR_STATIC_ASSERT(12 == kInt_GrSLType); | 153 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
151 GR_STATIC_ASSERT(13 == kUint_GrSLType); | 154 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
152 GR_STATIC_ASSERT(14 == kGrSLTypeCount); | 155 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
| 156 GR_STATIC_ASSERT(15 == kGrSLTypeCount); |
153 } | 157 } |
154 | 158 |
155 /** Is the shading language type numeric (including vectors/matrices)? */ | 159 /** Is the shading language type numeric (including vectors/matrices)? */ |
156 static inline bool GrSLTypeIsNumeric(GrSLType type) { | 160 static inline bool GrSLTypeIsNumeric(GrSLType type) { |
157 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type); | 161 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type); |
158 } | 162 } |
159 | 163 |
160 /** Returns the size in bytes for floating point GrSLTypes. For non floating poi
nt type returns 0 */ | 164 /** Returns the size in bytes for floating point GrSLTypes. For non floating poi
nt type returns 0 */ |
161 static inline size_t GrSLTypeSize(GrSLType type) { | 165 static inline size_t GrSLTypeSize(GrSLType type) { |
162 SkASSERT(GrSLTypeIsFloatType(type)); | 166 SkASSERT(GrSLTypeIsFloatType(type)); |
163 static const size_t kSizes[] = { | 167 static const size_t kSizes[] = { |
164 0, // kVoid_GrSLType | 168 0, // kVoid_GrSLType |
165 sizeof(float), // kFloat_GrSLType | 169 sizeof(float), // kFloat_GrSLType |
166 2 * sizeof(float), // kVec2f_GrSLType | 170 2 * sizeof(float), // kVec2f_GrSLType |
167 3 * sizeof(float), // kVec3f_GrSLType | 171 3 * sizeof(float), // kVec3f_GrSLType |
168 4 * sizeof(float), // kVec4f_GrSLType | 172 4 * sizeof(float), // kVec4f_GrSLType |
169 2 * 2 * sizeof(float), // kMat22f_GrSLType | 173 2 * 2 * sizeof(float), // kMat22f_GrSLType |
170 3 * 3 * sizeof(float), // kMat33f_GrSLType | 174 3 * 3 * sizeof(float), // kMat33f_GrSLType |
171 4 * 4 * sizeof(float), // kMat44f_GrSLType | 175 4 * 4 * sizeof(float), // kMat44f_GrSLType |
172 0, // kSampler2D_GrSLType | 176 0, // kSampler2D_GrSLType |
173 0, // kSamplerExternal_GrSLType | 177 0, // kSamplerExternal_GrSLType |
174 0, // kSampler2DRect_GrSLType | 178 0, // kSampler2DRect_GrSLType |
| 179 0, // kSamplerBuffer_GrSLType |
175 0, // kBool_GrSLType | 180 0, // kBool_GrSLType |
176 0, // kInt_GrSLType | 181 0, // kInt_GrSLType |
177 0, // kUint_GrSLType | 182 0, // kUint_GrSLType |
178 }; | 183 }; |
179 return kSizes[type]; | 184 return kSizes[type]; |
180 | 185 |
181 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 186 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
182 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 187 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
183 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 188 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
184 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 189 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
185 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 190 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
186 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); | 191 GR_STATIC_ASSERT(5 == kMat22f_GrSLType); |
187 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); | 192 GR_STATIC_ASSERT(6 == kMat33f_GrSLType); |
188 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); | 193 GR_STATIC_ASSERT(7 == kMat44f_GrSLType); |
189 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 194 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); |
190 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 195 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); |
191 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 196 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
192 GR_STATIC_ASSERT(11 == kBool_GrSLType); | 197 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); |
193 GR_STATIC_ASSERT(12 == kInt_GrSLType); | 198 GR_STATIC_ASSERT(12 == kBool_GrSLType); |
194 GR_STATIC_ASSERT(13 == kUint_GrSLType); | 199 GR_STATIC_ASSERT(13 == kInt_GrSLType); |
195 GR_STATIC_ASSERT(14 == kGrSLTypeCount); | 200 GR_STATIC_ASSERT(14 == kUint_GrSLType); |
| 201 GR_STATIC_ASSERT(15 == kGrSLTypeCount); |
196 } | 202 } |
197 | 203 |
198 static inline bool GrSLTypeIsSamplerType(GrSLType type) { | 204 static inline bool GrSLTypeIs2DTextureType(GrSLType type) { |
199 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 205 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
200 return type >= kSampler2D_GrSLType && type <= kSampler2DRect_GrSLType; | 206 return type >= kSampler2D_GrSLType && type <= kSampler2DRect_GrSLType; |
201 | 207 |
202 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); | 208 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); |
203 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); | 209 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); |
204 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); | 210 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
205 } | 211 } |
206 | 212 |
| 213 static inline bool GrSLTypeIsSamplerType(GrSLType type) { |
| 214 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 215 return type >= kSampler2D_GrSLType && type <= kSamplerBuffer_GrSLType; |
| 216 |
| 217 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType); |
| 218 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType); |
| 219 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType); |
| 220 GR_STATIC_ASSERT(11 == kSamplerBuffer_GrSLType); |
| 221 } |
| 222 |
207 static inline bool GrSLTypeAcceptsPrecision(GrSLType type) { | 223 static inline bool GrSLTypeAcceptsPrecision(GrSLType type) { |
208 return GrSLTypeIsNumeric(type) || GrSLTypeIsSamplerType(type); | 224 return GrSLTypeIsNumeric(type) || GrSLTypeIsSamplerType(type); |
209 } | 225 } |
210 | 226 |
211 ////////////////////////////////////////////////////////////////////////////// | 227 ////////////////////////////////////////////////////////////////////////////// |
212 | 228 |
213 /** | 229 /** |
214 * Types used to describe format of vertices in arrays. | 230 * Types used to describe format of vertices in arrays. |
215 */ | 231 */ |
216 enum GrVertexAttribType { | 232 enum GrVertexAttribType { |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // Takes a pointer to a GrCaps, and will suppress prints if required | 458 // Takes a pointer to a GrCaps, and will suppress prints if required |
443 #define GrCapsDebugf(caps, ...) \ | 459 #define GrCapsDebugf(caps, ...) \ |
444 if (!caps->suppressPrints()) { \ | 460 if (!caps->suppressPrints()) { \ |
445 SkDebugf(__VA_ARGS__); \ | 461 SkDebugf(__VA_ARGS__); \ |
446 } | 462 } |
447 #else | 463 #else |
448 #define GrCapsDebugf(caps, ...) | 464 #define GrCapsDebugf(caps, ...) |
449 #endif | 465 #endif |
450 | 466 |
451 #endif | 467 #endif |
OLD | NEW |