Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: include/gpu/GrTypesPriv.h

Issue 13296005: Revise attribute binding interface (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fix fExperimentalGS in GrGLProgramDesc Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkTArray.h ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkTArray.h" 12 #include "SkTArray.h"
12 13
13 /** 14 /**
14 * Types of shader-language-specific boxed variables we can create. 15 * Types of shader-language-specific boxed variables we can create. (Currently o nly GrGLShaderVars,
15 * (Currently only GrGLShaderVars, but should be applicable to other shader 16 * but should be applicable to other shader languages.)
16 * 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 kMat33f_GrSLType, 24 kMat33f_GrSLType,
25 kMat44f_GrSLType, 25 kMat44f_GrSLType,
26 kSampler2D_GrSLType 26 kSampler2D_GrSLType,
27
28 kLast_GrSLType = kSampler2D_GrSLType
27 }; 29 };
30 static const int kGrSLTypeCount = kLast_GrSLType + 1;
28 31
29 /** 32 /**
30 * Types used to describe format of vertices in arrays 33 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample rs.
34 */
35 static inline int GrSLTypeVectorCount(GrSLType type) {
36 GrAssert(type >= 0 && type < kGrSLTypeCount);
37 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1 };
38 return kCounts[type];
39
40 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
41 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
42 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
43 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
44 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
45 GR_STATIC_ASSERT(5 == kMat33f_GrSLType);
46 GR_STATIC_ASSERT(6 == kMat44f_GrSLType);
47 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType);
48 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
49 }
50
51 static inline GrSLType GrSLFloatVectorType(int count) {
52 GrAssert(count > 0 && count <= 4);
53 return (GrSLType)(count);
54
55 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
56 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
57 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
58 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
59 }
60
61 /**
62 * Types used to describe format of vertices in arrays.
31 */ 63 */
32 enum GrVertexAttribType { 64 enum GrVertexAttribType {
33 kFloat_GrVertexAttribType = 0, 65 kFloat_GrVertexAttribType = 0,
34 kVec2f_GrVertexAttribType, 66 kVec2f_GrVertexAttribType,
35 kVec3f_GrVertexAttribType, 67 kVec3f_GrVertexAttribType,
36 kVec4f_GrVertexAttribType, 68 kVec4f_GrVertexAttribType,
37 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors 69 kVec4ub_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors
38 70
39 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType 71 kLast_GrVertexAttribType = kVec4ub_GrVertexAttribType
40 }; 72 };
41 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; 73 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
42 74
75 /**
76 * Returns the vector size of the type.
77 */
78 static inline int GrVertexAttribTypeVectorCount(GrVertexAttribType type) {
79 GrAssert(type >= 0 && type < kGrVertexAttribTypeCount);
80 static const int kCounts[] = { 1, 2, 3, 4, 4 };
81 return kCounts[type];
82
83 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
84 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
85 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
86 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
87 GR_STATIC_ASSERT(4 == kVec4ub_GrVertexAttribType);
88 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kCounts) == kGrVertexAttribTypeCount);
89 }
90
91 /**
92 * Returns the size of the attrib type in bytes.
93 */
94 static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) {
95 GrAssert(type >= 0 && type < kGrVertexAttribTypeCount);
96 static const size_t kSizes[] = {
97 sizeof(float), // kFloat_GrVertexAttribType
98 2*sizeof(float), // kVec2f_GrVertexAttribType
99 3*sizeof(float), // kVec3f_GrVertexAttribType
100 4*sizeof(float), // kVec4f_GrVertexAttribType
101 4*sizeof(char) // kVec4ub_GrVertexAttribType
102 };
103 return kSizes[type];
104
105 GR_STATIC_ASSERT(0 == kFloat_GrVertexAttribType);
106 GR_STATIC_ASSERT(1 == kVec2f_GrVertexAttribType);
107 GR_STATIC_ASSERT(2 == kVec3f_GrVertexAttribType);
108 GR_STATIC_ASSERT(3 == kVec4f_GrVertexAttribType);
109 GR_STATIC_ASSERT(4 == kVec4ub_GrVertexAttribType);
110 GR_STATIC_ASSERT(GR_ARRAY_COUNT(kSizes) == kGrVertexAttribTypeCount);
111 }
112
113 /**
114 * Semantic bindings for vertex attributes. kEffect means that the attribute is input to a GrEffect.
115 * Each binding other than kEffect may not appear more than once in the current set of attributes.
116 * kPosition must be appear for exactly one attribute.
117 */
118 enum GrVertexAttribBinding {
119 kPosition_GrVertexAttribBinding, // required, must have vector count of 2
120 kLocalCoord_GrVertexAttribBinding, // must have vector count of 2
121 kColor_GrVertexAttribBinding, // must have vector count of 4
122 kCoverage_GrVertexAttribBinding, // must have vector count of 4
123
124 kLastFixedFunction_GrVertexAttribBinding = kCoverage_GrVertexAttribBinding,
125
126 kEffect_GrVertexAttribBinding, // vector length must agree with
127 // GrEffect::vertexAttribType() for each effect input to
128 // which the attribute is mapped by GrDr awState::setEffect()
129 kLast_GrVertexAttribBinding = kEffect_GrVertexAttribBinding
130 };
131
132 static const int kGrVertexAttribBindingCnt = kLast_GrVertexAttribBinding + 1;
133 static const int kGrFixedFunctionVertexAttribBindingCnt =
134 kLastFixedFunction_GrVertexAttribBinding + 1;
135
136 static const int GrFixedFunctionVertexAttribVectorCount(GrVertexAttribBinding bi nding) {
137 GrAssert(binding >= 0 && binding < kGrFixedFunctionVertexAttribBindingCnt);
138 static const int kVecCounts[] = { 2, 2, 4, 4 };
139
140 return kVecCounts[binding];
141
142 GR_STATIC_ASSERT(0 == kPosition_GrVertexAttribBinding);
143 GR_STATIC_ASSERT(1 == kLocalCoord_GrVertexAttribBinding);
144 GR_STATIC_ASSERT(2 == kColor_GrVertexAttribBinding);
145 GR_STATIC_ASSERT(3 == kCoverage_GrVertexAttribBinding);
146 GR_STATIC_ASSERT(kGrFixedFunctionVertexAttribBindingCnt == SK_ARRAY_COUNT(kV ecCounts));
147 }
148
43 struct GrVertexAttrib { 149 struct GrVertexAttrib {
44 inline void set(GrVertexAttribType type, size_t offset) { 150 inline void set(GrVertexAttribType type, size_t offset, GrVertexAttribBindin g binding) {
45 fType = type; fOffset = offset; 151 fType = type;
152 fOffset = offset;
153 fBinding = binding;
46 } 154 }
47 bool operator==(const GrVertexAttrib& other) const { 155 bool operator==(const GrVertexAttrib& other) const {
48 return fType == other.fType && fOffset == other.fOffset; 156 return fType == other.fType && fOffset == other.fOffset && fBinding == o ther.fBinding;
49 }; 157 };
50 bool operator!=(const GrVertexAttrib& other) const { return !(*this == other ); } 158 bool operator!=(const GrVertexAttrib& other) const { return !(*this == other ); }
51 159
52 GrVertexAttribType fType; 160 GrVertexAttribType fType;
53 size_t fOffset; 161 size_t fOffset;
162 GrVertexAttribBinding fBinding;
54 }; 163 };
55 164
56 template <int N> 165 template <int N> class GrVertexAttribArray : public SkSTArray<N, GrVertexAttrib, true> {};
57 class GrVertexAttribArray : public SkSTArray<N, GrVertexAttrib, true> {};
58 166
59 #endif 167 #endif
OLDNEW
« no previous file with comments | « include/core/SkTArray.h ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698