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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 suffixedVaryingName.append(suffix); | 94 suffixedVaryingName.append(suffix); |
95 varyingName = suffixedVaryingName.c_str(); | 95 varyingName = suffixedVaryingName.c_str(); |
96 } | 96 } |
97 const char* vsVaryingName; | 97 const char* vsVaryingName; |
98 const char* fsVaryingName; | 98 const char* fsVaryingName; |
99 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingName
); | 99 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingName
); |
100 | 100 |
101 const GrGLShaderVar* coords; | 101 const GrGLShaderVar* coords; |
102 switch (fCoordsType) { | 102 switch (fCoordsType) { |
103 case GrEffect::kLocal_CoordsType: | 103 case GrEffect::kLocal_CoordsType: |
104 GrAssert(!(kPositionCoords_Flag & key)); | 104 SkASSERT(!(kPositionCoords_Flag & key)); |
105 coords = &builder->localCoordsAttribute(); | 105 coords = &builder->localCoordsAttribute(); |
106 break; | 106 break; |
107 case GrEffect::kPosition_CoordsType: | 107 case GrEffect::kPosition_CoordsType: |
108 GrAssert((kPositionCoords_Flag & key) || !builder->hasExplicitLocalC
oords()); | 108 SkASSERT((kPositionCoords_Flag & key) || !builder->hasExplicitLocalC
oords()); |
109 coords = &builder->positionAttribute(); | 109 coords = &builder->positionAttribute(); |
110 break; | 110 break; |
111 default: | 111 default: |
112 coords = NULL; // prevents warning | 112 coords = NULL; // prevents warning |
113 GrCrash("Unexpected coords type."); | 113 GrCrash("Unexpected coords type."); |
114 } | 114 } |
115 // varying = matrix * coords (logically) | 115 // varying = matrix * coords (logically) |
116 switch (fUniType) { | 116 switch (fUniType) { |
117 case kVoid_GrSLType: | 117 case kVoid_GrSLType: |
118 GrAssert(kVec2f_GrSLType == varyingType); | 118 SkASSERT(kVec2f_GrSLType == varyingType); |
119 builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords->c_str(
)); | 119 builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords->c_str(
)); |
120 break; | 120 break; |
121 case kVec2f_GrSLType: | 121 case kVec2f_GrSLType: |
122 GrAssert(kVec2f_GrSLType == varyingType); | 122 SkASSERT(kVec2f_GrSLType == varyingType); |
123 builder->vsCodeAppendf("\t%s = %s + %s;\n", | 123 builder->vsCodeAppendf("\t%s = %s + %s;\n", |
124 vsVaryingName, uniName, coords->c_str()); | 124 vsVaryingName, uniName, coords->c_str()); |
125 break; | 125 break; |
126 case kMat33f_GrSLType: { | 126 case kMat33f_GrSLType: { |
127 GrAssert(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); | 127 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); |
128 if (kVec2f_GrSLType == varyingType) { | 128 if (kVec2f_GrSLType == varyingType) { |
129 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", | 129 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", |
130 vsVaryingName, uniName, coords->c_str()); | 130 vsVaryingName, uniName, coords->c_str()); |
131 } else { | 131 } else { |
132 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", | 132 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", |
133 vsVaryingName, uniName, coords->c_str()); | 133 vsVaryingName, uniName, coords->c_str()); |
134 } | 134 } |
135 break; | 135 break; |
136 } | 136 } |
137 default: | 137 default: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 if (NULL != vsVaryingType) { | 183 if (NULL != vsVaryingType) { |
184 *vsVaryingType = varyingType; | 184 *vsVaryingType = varyingType; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager, | 188 void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager, |
189 const SkMatrix& matrix, | 189 const SkMatrix& matrix, |
190 const GrDrawEffect& drawEffect, | 190 const GrDrawEffect& drawEffect, |
191 const GrTexture* texture) { | 191 const GrTexture* texture) { |
192 GrAssert(fUni.isValid() != (kVoid_GrSLType == fUniType)); | 192 SkASSERT(fUni.isValid() != (kVoid_GrSLType == fUniType)); |
193 const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsTy
pe ? | 193 const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsTy
pe ? |
194 drawEffect.getCoordChangeMatrix() : | 194 drawEffect.getCoordChangeMatrix() : |
195 SkMatrix::I(); | 195 SkMatrix::I(); |
196 switch (fUniType) { | 196 switch (fUniType) { |
197 case kVoid_GrSLType: | 197 case kVoid_GrSLType: |
198 GrAssert(matrix.isIdentity()); | 198 SkASSERT(matrix.isIdentity()); |
199 GrAssert(coordChangeMatrix.isIdentity()); | 199 SkASSERT(coordChangeMatrix.isIdentity()); |
200 GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); | 200 SkASSERT(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); |
201 return; | 201 return; |
202 case kVec2f_GrSLType: { | 202 case kVec2f_GrSLType: { |
203 GrAssert(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChang
eMatrix.getType())); | 203 SkASSERT(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChang
eMatrix.getType())); |
204 GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); | 204 SkASSERT(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); |
205 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMat
rix::kMTransX]; | 205 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMat
rix::kMTransX]; |
206 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMat
rix::kMTransY]; | 206 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMat
rix::kMTransY]; |
207 if (fPrevMatrix.get(SkMatrix::kMTransX) != tx || | 207 if (fPrevMatrix.get(SkMatrix::kMTransX) != tx || |
208 fPrevMatrix.get(SkMatrix::kMTransY) != ty) { | 208 fPrevMatrix.get(SkMatrix::kMTransY) != ty) { |
209 uniformManager.set2f(fUni, tx, ty); | 209 uniformManager.set2f(fUni, tx, ty); |
210 fPrevMatrix.set(SkMatrix::kMTransX, tx); | 210 fPrevMatrix.set(SkMatrix::kMTransX, tx); |
211 fPrevMatrix.set(SkMatrix::kMTransY, ty); | 211 fPrevMatrix.set(SkMatrix::kMTransY, ty); |
212 } | 212 } |
213 break; | 213 break; |
214 } | 214 } |
(...skipping 13 matching lines...) Expand all 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 |