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

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

Issue 1755483002: Add support for 2x2 matrices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: vk updates Created 4 years, 9 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
« no previous file with comments | « no previous file | src/gpu/gl/GrGLProgramDataManager.h » ('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 "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 kMat33f_GrSLType, 25 kMat33f_GrSLType,
25 kMat44f_GrSLType, 26 kMat44f_GrSLType,
26 kSampler2D_GrSLType, 27 kSampler2D_GrSLType,
27 kSamplerExternal_GrSLType, 28 kSamplerExternal_GrSLType,
28 kSampler2DRect_GrSLType, 29 kSampler2DRect_GrSLType,
29 kBool_GrSLType, 30 kBool_GrSLType,
30 kInt_GrSLType, 31 kInt_GrSLType,
31 kUint_GrSLType, 32 kUint_GrSLType,
32 33
33 kLast_GrSLType = kUint_GrSLType 34 kLast_GrSLType = kUint_GrSLType
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 kLast_GrSLPrecision = kHigh_GrSLPrecision 69 kLast_GrSLPrecision = kHigh_GrSLPrecision
69 }; 70 };
70 71
71 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; 72 static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1;
72 73
73 /** 74 /**
74 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample rs. 75 * Gets the vector size of the SLType. Returns -1 for void, matrices, and sample rs.
75 */ 76 */
76 static inline int GrSLTypeVectorCount(GrSLType type) { 77 static inline int GrSLTypeVectorCount(GrSLType type) {
77 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); 78 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
78 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, 1, 1, 1 } ; 79 static const int kCounts[] = { -1, 1, 2, 3, 4, -1, -1, -1, -1, -1, -1, 1, 1, 1 };
79 return kCounts[type]; 80 return kCounts[type];
80 81
81 GR_STATIC_ASSERT(0 == kVoid_GrSLType); 82 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
82 GR_STATIC_ASSERT(1 == kFloat_GrSLType); 83 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
83 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); 84 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
84 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); 85 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
85 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); 86 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
86 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); 87 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
87 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); 88 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
88 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); 89 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
89 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); 90 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
90 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); 91 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
91 GR_STATIC_ASSERT(10 == kBool_GrSLType); 92 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
92 GR_STATIC_ASSERT(11 == kInt_GrSLType); 93 GR_STATIC_ASSERT(11 == kBool_GrSLType);
93 GR_STATIC_ASSERT(12 == kUint_GrSLType); 94 GR_STATIC_ASSERT(12 == kInt_GrSLType);
95 GR_STATIC_ASSERT(13 == kUint_GrSLType);
94 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount); 96 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kCounts) == kGrSLTypeCount);
95 } 97 }
96 98
97 /** Return the type enum for a vector of floats of length n (1..4), 99 /** Return the type enum for a vector of floats of length n (1..4),
98 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */ 100 e.g. 1 -> kFloat_GrSLType, 2 -> kVec2_GrSLType, ... */
99 static inline GrSLType GrSLFloatVectorType(int count) { 101 static inline GrSLType GrSLFloatVectorType(int count) {
100 SkASSERT(count > 0 && count <= 4); 102 SkASSERT(count > 0 && count <= 4);
101 return (GrSLType)(count); 103 return (GrSLType)(count);
102 104
103 GR_STATIC_ASSERT(kFloat_GrSLType == 1); 105 GR_STATIC_ASSERT(kFloat_GrSLType == 1);
104 GR_STATIC_ASSERT(kVec2f_GrSLType == 2); 106 GR_STATIC_ASSERT(kVec2f_GrSLType == 2);
105 GR_STATIC_ASSERT(kVec3f_GrSLType == 3); 107 GR_STATIC_ASSERT(kVec3f_GrSLType == 3);
106 GR_STATIC_ASSERT(kVec4f_GrSLType == 4); 108 GR_STATIC_ASSERT(kVec4f_GrSLType == 4);
107 } 109 }
108 110
109 /** Is the shading language type float (including vectors/matrices)? */ 111 /** Is the shading language type float (including vectors/matrices)? */
110 static inline bool GrSLTypeIsFloatType(GrSLType type) { 112 static inline bool GrSLTypeIsFloatType(GrSLType type) {
111 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); 113 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
112 return (type >= 1 && type <= 6); 114 return type >= kFloat_GrSLType && type <= kMat44f_GrSLType;
113 115
114 GR_STATIC_ASSERT(0 == kVoid_GrSLType); 116 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
115 GR_STATIC_ASSERT(1 == kFloat_GrSLType); 117 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
116 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); 118 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
117 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); 119 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
118 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); 120 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
119 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); 121 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
120 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); 122 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
121 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); 123 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
122 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); 124 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
123 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); 125 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
124 GR_STATIC_ASSERT(10 == kBool_GrSLType); 126 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
125 GR_STATIC_ASSERT(11 == kInt_GrSLType); 127 GR_STATIC_ASSERT(11 == kBool_GrSLType);
126 GR_STATIC_ASSERT(12 == kUint_GrSLType); 128 GR_STATIC_ASSERT(12 == kInt_GrSLType);
127 GR_STATIC_ASSERT(13 == kGrSLTypeCount); 129 GR_STATIC_ASSERT(13 == kUint_GrSLType);
130 GR_STATIC_ASSERT(14 == kGrSLTypeCount);
128 } 131 }
129 132
130 /** Is the shading language type integral (including vectors/matrices)? */ 133 /** Is the shading language type integral (including vectors/matrices)? */
131 static inline bool GrSLTypeIsIntType(GrSLType type) { 134 static inline bool GrSLTypeIsIntType(GrSLType type) {
132 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); 135 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
133 return type >= kInt_GrSLType; 136 return type >= kInt_GrSLType;
134 137
135 GR_STATIC_ASSERT(0 == kVoid_GrSLType); 138 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
136 GR_STATIC_ASSERT(1 == kFloat_GrSLType); 139 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
137 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); 140 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
138 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); 141 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
139 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); 142 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
140 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); 143 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
141 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); 144 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
142 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); 145 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
143 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); 146 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
144 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); 147 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
145 GR_STATIC_ASSERT(10 == kBool_GrSLType); 148 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
146 GR_STATIC_ASSERT(11 == kInt_GrSLType); 149 GR_STATIC_ASSERT(11 == kBool_GrSLType);
147 GR_STATIC_ASSERT(12 == kUint_GrSLType); 150 GR_STATIC_ASSERT(12 == kInt_GrSLType);
148 GR_STATIC_ASSERT(13 == kGrSLTypeCount); 151 GR_STATIC_ASSERT(13 == kUint_GrSLType);
152 GR_STATIC_ASSERT(14 == kGrSLTypeCount);
149 } 153 }
150 154
151 /** Is the shading language type numeric (including vectors/matrices)? */ 155 /** Is the shading language type numeric (including vectors/matrices)? */
152 static inline bool GrSLTypeIsNumeric(GrSLType type) { 156 static inline bool GrSLTypeIsNumeric(GrSLType type) {
153 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type); 157 return GrSLTypeIsFloatType(type) || GrSLTypeIsIntType(type);
154 } 158 }
155 159
156 /** Returns the size in bytes for floating point GrSLTypes. For non floating poi nt type returns 0 */ 160 /** Returns the size in bytes for floating point GrSLTypes. For non floating poi nt type returns 0 */
157 static inline size_t GrSLTypeSize(GrSLType type) { 161 static inline size_t GrSLTypeSize(GrSLType type) {
158 SkASSERT(GrSLTypeIsFloatType(type)); 162 SkASSERT(GrSLTypeIsFloatType(type));
159 static const size_t kSizes[] = { 163 static const size_t kSizes[] = {
160 0, // kVoid_GrSLType 164 0, // kVoid_GrSLType
161 sizeof(float), // kFloat_GrSLType 165 sizeof(float), // kFloat_GrSLType
162 2 * sizeof(float), // kVec2f_GrSLType 166 2 * sizeof(float), // kVec2f_GrSLType
163 3 * sizeof(float), // kVec3f_GrSLType 167 3 * sizeof(float), // kVec3f_GrSLType
164 4 * sizeof(float), // kVec4f_GrSLType 168 4 * sizeof(float), // kVec4f_GrSLType
165 9 * sizeof(float), // kMat33f_GrSLType 169 2 * 2 * sizeof(float), // kMat22f_GrSLType
166 16 * sizeof(float), // kMat44f_GrSLType 170 3 * 3 * sizeof(float), // kMat33f_GrSLType
171 4 * 4 * sizeof(float), // kMat44f_GrSLType
167 0, // kSampler2D_GrSLType 172 0, // kSampler2D_GrSLType
168 0, // kSamplerExternal_GrSLType 173 0, // kSamplerExternal_GrSLType
169 0, // kSampler2DRect_GrSLType 174 0, // kSampler2DRect_GrSLType
170 0, // kBool_GrSLType 175 0, // kBool_GrSLType
171 0, // kInt_GrSLType 176 0, // kInt_GrSLType
172 0, // kUint_GrSLType 177 0, // kUint_GrSLType
173 }; 178 };
174 return kSizes[type]; 179 return kSizes[type];
175 180
176 GR_STATIC_ASSERT(0 == kVoid_GrSLType); 181 GR_STATIC_ASSERT(0 == kVoid_GrSLType);
177 GR_STATIC_ASSERT(1 == kFloat_GrSLType); 182 GR_STATIC_ASSERT(1 == kFloat_GrSLType);
178 GR_STATIC_ASSERT(2 == kVec2f_GrSLType); 183 GR_STATIC_ASSERT(2 == kVec2f_GrSLType);
179 GR_STATIC_ASSERT(3 == kVec3f_GrSLType); 184 GR_STATIC_ASSERT(3 == kVec3f_GrSLType);
180 GR_STATIC_ASSERT(4 == kVec4f_GrSLType); 185 GR_STATIC_ASSERT(4 == kVec4f_GrSLType);
181 GR_STATIC_ASSERT(5 == kMat33f_GrSLType); 186 GR_STATIC_ASSERT(5 == kMat22f_GrSLType);
182 GR_STATIC_ASSERT(6 == kMat44f_GrSLType); 187 GR_STATIC_ASSERT(6 == kMat33f_GrSLType);
183 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); 188 GR_STATIC_ASSERT(7 == kMat44f_GrSLType);
184 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); 189 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
185 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); 190 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
186 GR_STATIC_ASSERT(10 == kBool_GrSLType); 191 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
187 GR_STATIC_ASSERT(11 == kInt_GrSLType); 192 GR_STATIC_ASSERT(11 == kBool_GrSLType);
188 GR_STATIC_ASSERT(12 == kUint_GrSLType); 193 GR_STATIC_ASSERT(12 == kInt_GrSLType);
189 GR_STATIC_ASSERT(13 == kGrSLTypeCount); 194 GR_STATIC_ASSERT(13 == kUint_GrSLType);
195 GR_STATIC_ASSERT(14 == kGrSLTypeCount);
190 } 196 }
191 197
192 static inline bool GrSLTypeIsSamplerType(GrSLType type) { 198 static inline bool GrSLTypeIsSamplerType(GrSLType type) {
193 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount)); 199 SkASSERT(type >= 0 && type < static_cast<GrSLType>(kGrSLTypeCount));
194 return type >= 7 && type <= 9; 200 return type >= kSampler2D_GrSLType && type <= kSampler2DRect_GrSLType;
195 201
196 GR_STATIC_ASSERT(7 == kSampler2D_GrSLType); 202 GR_STATIC_ASSERT(8 == kSampler2D_GrSLType);
197 GR_STATIC_ASSERT(8 == kSamplerExternal_GrSLType); 203 GR_STATIC_ASSERT(9 == kSamplerExternal_GrSLType);
198 GR_STATIC_ASSERT(9 == kSampler2DRect_GrSLType); 204 GR_STATIC_ASSERT(10 == kSampler2DRect_GrSLType);
199 } 205 }
200 206
201 ////////////////////////////////////////////////////////////////////////////// 207 //////////////////////////////////////////////////////////////////////////////
202 208
203 /** 209 /**
204 * Types used to describe format of vertices in arrays. 210 * Types used to describe format of vertices in arrays.
205 */ 211 */
206 enum GrVertexAttribType { 212 enum GrVertexAttribType {
207 kFloat_GrVertexAttribType = 0, 213 kFloat_GrVertexAttribType = 0,
208 kVec2f_GrVertexAttribType, 214 kVec2f_GrVertexAttribType,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // Takes a pointer to a GrCaps, and will suppress prints if required 411 // Takes a pointer to a GrCaps, and will suppress prints if required
406 #define GrCapsDebugf(caps, ...) \ 412 #define GrCapsDebugf(caps, ...) \
407 if (!caps->suppressPrints()) { \ 413 if (!caps->suppressPrints()) { \
408 SkDebugf(__VA_ARGS__); \ 414 SkDebugf(__VA_ARGS__); \
409 } 415 }
410 #else 416 #else
411 #define GrCapsDebugf(caps, ...) 417 #define GrCapsDebugf(caps, ...)
412 #endif 418 #endif
413 419
414 #endif 420 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/gl/GrGLProgramDataManager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698