| 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 kSampler2D_GrSLType, | 26 kSampler2D_GrSLType, |
| 27 | 27 |
| 28 kLast_GrSLType = kSampler2D_GrSLType | 28 kLast_GrSLType = kSampler2D_GrSLType |
| 29 }; | 29 }; |
| 30 static const int kGrSLTypeCount = kLast_GrSLType + 1; | 30 static const int kGrSLTypeCount = kLast_GrSLType + 1; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. | 33 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample
rs. |
| 34 */ | 34 */ |
| 35 static inline int GrSLTypeVectorCount(GrSLType type) { | 35 static inline int GrSLTypeVectorCount(GrSLType type) { |
| 36 GrAssert(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); | 36 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); |
| 37 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 }; | 37 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 }; |
| 38 return kCounts[type]; | 38 return kCounts[type]; |
| 39 | 39 |
| 40 GR_STATIC_ASSERT(0 == kVoid_GrSLType); | 40 GR_STATIC_ASSERT(0 == kVoid_GrSLType); |
| 41 GR_STATIC_ASSERT(1 == kFloat_GrSLType); | 41 GR_STATIC_ASSERT(1 == kFloat_GrSLType); |
| 42 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); | 42 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); |
| 43 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); | 43 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); |
| 44 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); | 44 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); |
| 45 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); | 45 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); |
| 46 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); | 46 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); |
| 47 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); | 47 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); |
| 48 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kCounts) == kGrSLTypeCount); | 48 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kCounts) == kGrSLTypeCount); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** Return the type enum for a vector of floats of length n (1..4), | 51 /** Return the type enum for a vector of floats of length n (1..4), |
| 52 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ | 52 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ |
| 53 static inline GrSLType GrSLFloatVectorType(int count) { | 53 static inline GrSLType GrSLFloatVectorType(int count) { |
| 54 GrAssert(count > 0 && count <= 4); | 54 SkASSERT(count > 0 && count <= 4); |
| 55 return (GrSLType)(count); | 55 return (GrSLType)(count); |
| 56 | 56 |
| 57 GR_STATIC_ASSERT(kFloat_GrSLType == 1); | 57 GR_STATIC_ASSERT(kFloat_GrSLType == 1); |
| 58 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); | 58 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); |
| 59 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); | 59 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); |
| 60 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); | 60 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * Types used to describe format of vertices in arrays. | 64 * Types used to describe format of vertices in arrays. |
| 65 */ | 65 */ |
| 66 enum GrVertexAttribType { | 66 enum GrVertexAttribType { |
| 67 kFloat_GrVertexAttribType = 0, | 67 kFloat_GrVertexAttribType = 0, |
| 68 kVec2f_GrVertexAttribType, | 68 kVec2f_GrVertexAttribType, |
| 69 kVec3f_GrVertexAttribType, | 69 kVec3f_GrVertexAttribType, |
| 70 kVec4f_GrVertexAttribType, | 70 kVec4f_GrVertexAttribType, |
| 71 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors | 71 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors |
| 72 | 72 |
| 73 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType | 73 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType |
| 74 }; | 74 }; |
| 75 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; | 75 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Returns the vector size of the type. | 78 * Returns the vector size of the type. |
| 79 */ | 79 */ |
| 80 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { | 80 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) { |
| 81 GrAssert(type >= 0 && type < kGrVertexAttribTypeCount); | 81 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
| 82 static const int kCounts[] = { 1, 2, 3, 4, 4 }; | 82 static const int kCounts[] = { 1, 2, 3, 4, 4 }; |
| 83 return kCounts[type]; | 83 return kCounts[type]; |
| 84 | 84 |
| 85 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); | 85 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| 86 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); | 86 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType); |
| 87 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); | 87 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType); |
| 88 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); | 88 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType); |
| 89 GR_STATIC_ASSERT(4 == kVec4ub_GrVertexAttribType); | 89 GR_STATIC_ASSERT(4 == kVec4ub_GrVertexAttribType); |
| 90 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); | 90 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount); |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Returns the size of the attrib type in bytes. | 94 * Returns the size of the attrib type in bytes. |
| 95 */ | 95 */ |
| 96 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { | 96 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { |
| 97 GrAssert(type >= 0 && type < kGrVertexAttribTypeCount); | 97 SkASSERT(type >= 0 && type < kGrVertexAttribTypeCount); |
| 98 static const size_t kSizes[] = { | 98 static const size_t kSizes[] = { |
| 99 sizeof(float), // kFloat_GrVertexAttribType | 99 sizeof(float), // kFloat_GrVertexAttribType |
| 100 2*sizeof(float), // kVec2f_GrVertexAttribType | 100 2*sizeof(float), // kVec2f_GrVertexAttribType |
| 101 3*sizeof(float), // kVec3f_GrVertexAttribType | 101 3*sizeof(float), // kVec3f_GrVertexAttribType |
| 102 4*sizeof(float), // kVec4f_GrVertexAttribType | 102 4*sizeof(float), // kVec4f_GrVertexAttribType |
| 103 4*sizeof(char) // kVec4ub_GrVertexAttribType | 103 4*sizeof(char) // kVec4ub_GrVertexAttribType |
| 104 }; | 104 }; |
| 105 return kSizes[type]; | 105 return kSizes[type]; |
| 106 | 106 |
| 107 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); | 107 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 129 // GrEffect::vertexAttribType() for each
effect input to | 129 // GrEffect::vertexAttribType() for each
effect input to |
| 130 // which the attribute is mapped by GrDr
awState::setEffect() | 130 // which the attribute is mapped by GrDr
awState::setEffect() |
| 131 kLast_GrVertexAttribBinding = kEffect_GrVertexAttribBinding | 131 kLast_GrVertexAttribBinding = kEffect_GrVertexAttribBinding |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 static const int kGrVertexAttribBindingCnt = kLast_GrVertexAttribBinding + 1; | 134 static const int kGrVertexAttribBindingCnt = kLast_GrVertexAttribBinding + 1; |
| 135 static const int kGrFixedFunctionVertexAttribBindingCnt = | 135 static const int kGrFixedFunctionVertexAttribBindingCnt = |
| 136 kLastFixedFunction_GrVertexAttribBinding + 1; | 136 kLastFixedFunction_GrVertexAttribBinding + 1; |
| 137 | 137 |
| 138 static inline int GrFixedFunctionVertexAttribVectorCount(GrVertexAttribBinding b
inding) { | 138 static inline int GrFixedFunctionVertexAttribVectorCount(GrVertexAttribBinding b
inding) { |
| 139 GrAssert(binding >= 0 && binding < kGrFixedFunctionVertexAttribBindingCnt); | 139 SkASSERT(binding >= 0 && binding < kGrFixedFunctionVertexAttribBindingCnt); |
| 140 static const int kVecCounts[] = { 2, 2, 4, 4 }; | 140 static const int kVecCounts[] = { 2, 2, 4, 4 }; |
| 141 | 141 |
| 142 return kVecCounts[binding]; | 142 return kVecCounts[binding]; |
| 143 | 143 |
| 144 GR_STATIC_ASSERT(0 == kPosition_GrVertexAttribBinding); | 144 GR_STATIC_ASSERT(0 == kPosition_GrVertexAttribBinding); |
| 145 GR_STATIC_ASSERT(1 == kLocalCoord_GrVertexAttribBinding); | 145 GR_STATIC_ASSERT(1 == kLocalCoord_GrVertexAttribBinding); |
| 146 GR_STATIC_ASSERT(2 == kColor_GrVertexAttribBinding); | 146 GR_STATIC_ASSERT(2 == kColor_GrVertexAttribBinding); |
| 147 GR_STATIC_ASSERT(3 == kCoverage_GrVertexAttribBinding); | 147 GR_STATIC_ASSERT(3 == kCoverage_GrVertexAttribBinding); |
| 148 GR_STATIC_ASSERT(kGrFixedFunctionVertexAttribBindingCnt == SK_ARRAY_COUNT(kV
ecCounts)); | 148 GR_STATIC_ASSERT(kGrFixedFunctionVertexAttribBindingCnt == SK_ARRAY_COUNT(kV
ecCounts)); |
| 149 } | 149 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 bool operator!=(const GrVertexAttrib& other) const { return !(*this == other
); } | 160 bool operator!=(const GrVertexAttrib& other) const { return !(*this == other
); } |
| 161 | 161 |
| 162 GrVertexAttribType fType; | 162 GrVertexAttribType fType; |
| 163 size_t fOffset; | 163 size_t fOffset; |
| 164 GrVertexAttribBinding fBinding; | 164 GrVertexAttribBinding fBinding; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 template <int N> class GrVertexAttribArray : public SkSTArray<N, GrVertexAttrib,
true> {}; | 167 template <int N> class GrVertexAttribArray : public SkSTArray<N, GrVertexAttrib,
true> {}; |
| 168 | 168 |
| 169 #endif | 169 #endif |
| OLD | NEW |