OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "GrGLEffectMatrix.h" | 8 #include "GrGLEffectMatrix.h" |
9 #include "GrDrawEffect.h" | 9 #include "GrDrawEffect.h" |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } else if (SkMatrix::kTranslate_Mask & combinedTypes) { | 38 } else if (SkMatrix::kTranslate_Mask & combinedTypes) { |
39 key |= kTrans_MatrixType; | 39 key |= kTrans_MatrixType; |
40 } else { | 40 } else { |
41 key |= kIdentity_MatrixType; | 41 key |= kIdentity_MatrixType; |
42 } | 42 } |
43 return key; | 43 return key; |
44 } | 44 } |
45 | 45 |
46 GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder, | 46 GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder, |
47 EffectKey key, | 47 EffectKey key, |
48 const char** fsCoordName, | 48 SkString* fsCoordName, |
49 const char** vsCoordName, | 49 SkString* vsCoordName, |
50 const char* suffix) { | 50 const char* suffix) { |
51 GrSLType varyingType = kVoid_GrSLType; | 51 GrSLType varyingType = kVoid_GrSLType; |
52 const char* uniName; | 52 const char* uniName; |
53 key &= kKeyMask; | 53 key &= kKeyMask; |
54 switch (key & kMatrixTypeKeyMask) { | 54 switch (key & kMatrixTypeKeyMask) { |
55 case kIdentity_MatrixType: | 55 case kIdentity_MatrixType: |
56 fUniType = kVoid_GrSLType; | 56 fUniType = kVoid_GrSLType; |
57 varyingType = kVec2f_GrSLType; | 57 varyingType = kVec2f_GrSLType; |
58 break; | 58 break; |
59 case kTrans_MatrixType: | 59 case kTrans_MatrixType: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 return varyingType; | 146 return varyingType; |
147 } | 147 } |
148 | 148 |
149 /** | 149 /** |
150 * This is similar to emitCode except that it performs perspective division i
n the FS if the | 150 * This is similar to emitCode except that it performs perspective division i
n the FS if the |
151 * texture coordinates have a w coordinate. The fsCoordName always refers to
a vec2f. | 151 * texture coordinates have a w coordinate. The fsCoordName always refers to
a vec2f. |
152 */ | 152 */ |
153 void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder, | 153 void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder, |
154 EffectKey key, | 154 EffectKey key, |
155 const char** fsCoordName, | 155 SkString* fsCoordName, |
156 const char** vsVaryingName, | 156 SkString* vsVaryingName, |
157 GrSLType* vsVaryingType, | 157 GrSLType* vsVaryingType, |
158 const char* suffix) { | 158 const char* suffix) { |
159 const char* fsVaryingName; | 159 SkString fsVaryingName; |
160 | 160 |
161 GrSLType varyingType = this->emitCode(builder, | 161 GrSLType varyingType = this->emitCode(builder, |
162 key, | 162 key, |
163 &fsVaryingName, | 163 &fsVaryingName, |
164 vsVaryingName, | 164 vsVaryingName, |
165 suffix); | 165 suffix); |
166 if (kVec3f_GrSLType == varyingType) { | 166 if (kVec3f_GrSLType == varyingType) { |
167 | 167 |
168 const char* coordName = "coords2D"; | 168 const char* coordName = "coords2D"; |
169 SkString suffixedCoordName; | 169 SkString suffixedCoordName; |
170 if (NULL != suffix) { | 170 if (NULL != suffix) { |
171 suffixedCoordName.append(coordName); | 171 suffixedCoordName.append(coordName); |
172 suffixedCoordName.append(suffix); | 172 suffixedCoordName.append(suffix); |
173 coordName = suffixedCoordName.c_str(); | 173 coordName = suffixedCoordName.c_str(); |
174 } | 174 } |
175 builder->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;", | 175 builder->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;", |
176 coordName, fsVaryingName, fsVaryingName); | 176 coordName, fsVaryingName.c_str(), fsVaryingName.c
_str()); |
177 if (NULL != fsCoordName) { | 177 if (NULL != fsCoordName) { |
178 *fsCoordName = coordName; | 178 *fsCoordName = coordName; |
179 } | 179 } |
180 } else if(NULL != fsCoordName) { | 180 } else if(NULL != fsCoordName) { |
181 *fsCoordName = fsVaryingName; | 181 *fsCoordName = fsVaryingName; |
182 } | 182 } |
183 if (NULL != vsVaryingType) { | 183 if (NULL != vsVaryingType) { |
184 *vsVaryingType = varyingType; | 184 *vsVaryingType = varyingType; |
185 } | 185 } |
186 } | 186 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (!fPrevMatrix.cheapEqualTo(combined)) { | 228 if (!fPrevMatrix.cheapEqualTo(combined)) { |
229 uniformManager.setSkMatrix(fUni, combined); | 229 uniformManager.setSkMatrix(fUni, combined); |
230 fPrevMatrix = combined; | 230 fPrevMatrix = combined; |
231 } | 231 } |
232 break; | 232 break; |
233 } | 233 } |
234 default: | 234 default: |
235 GrCrash("Unexpected uniform type."); | 235 GrCrash("Unexpected uniform type."); |
236 } | 236 } |
237 } | 237 } |
OLD | NEW |