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 30 matching lines...) Expand all Loading... |
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 SkString* fsCoordName, | 48 SkString* fsCoordName, |
49 SkString* vsCoordName, | 49 SkString* vsCoordName, |
50 const char* suffix) { | 50 const char* suffix) { |
51 // TODO: Handle vertexless shaders here before we start enabling them. | |
52 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(
); | |
53 SkASSERT(NULL != vertexBuilder); | |
54 | |
55 GrSLType varyingType = kVoid_GrSLType; | 51 GrSLType varyingType = kVoid_GrSLType; |
56 const char* uniName; | 52 const char* uniName; |
57 key &= kKeyMask; | 53 key &= kKeyMask; |
58 switch (key & kMatrixTypeKeyMask) { | 54 switch (key & kMatrixTypeKeyMask) { |
59 case kIdentity_MatrixType: | 55 case kIdentity_MatrixType: |
60 fUniType = kVoid_GrSLType; | 56 fUniType = kVoid_GrSLType; |
61 varyingType = kVec2f_GrSLType; | 57 varyingType = kVec2f_GrSLType; |
62 break; | 58 break; |
63 case kTrans_MatrixType: | 59 case kTrans_MatrixType: |
64 fUniType = kVec2f_GrSLType; | 60 fUniType = kVec2f_GrSLType; |
65 uniName = "StageTranslate"; | 61 uniName = "StageTranslate"; |
66 varyingType = kVec2f_GrSLType; | 62 varyingType = kVec2f_GrSLType; |
67 break; | 63 break; |
68 case kNoPersp_MatrixType: | 64 case kNoPersp_MatrixType: |
69 fUniType = kMat33f_GrSLType; | 65 fUniType = kMat33f_GrSLType; |
70 uniName = "StageMatrix"; | 66 uniName = "StageMatrix"; |
71 varyingType = kVec2f_GrSLType; | 67 varyingType = kVec2f_GrSLType; |
72 break; | 68 break; |
73 case kGeneral_MatrixType: | 69 case kGeneral_MatrixType: |
74 fUniType = kMat33f_GrSLType; | 70 fUniType = kMat33f_GrSLType; |
75 uniName = "StageMatrix"; | 71 uniName = "StageMatrix"; |
76 varyingType = kVec3f_GrSLType; | 72 varyingType = kVec3f_GrSLType; |
77 break; | 73 break; |
78 default: | 74 default: |
79 GrCrash("Unexpected key."); | 75 GrCrash("Unexpected key."); |
80 } | 76 } |
| 77 |
| 78 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(
); |
| 79 if (NULL == vertexBuilder) { |
| 80 if (vsCoordName) { |
| 81 vsCoordName->reset(); |
| 82 } |
| 83 builder->addTexGenUnit(varyingType, fsCoordName, &fTexGenUnit, &fNumTexG
enComponents); |
| 84 return varyingType; |
| 85 } |
| 86 |
81 SkString suffixedUniName; | 87 SkString suffixedUniName; |
82 if (NULL != suffix) { | 88 if (NULL != suffix) { |
83 suffixedUniName.append(uniName); | 89 suffixedUniName.append(uniName); |
84 suffixedUniName.append(suffix); | 90 suffixedUniName.append(suffix); |
85 uniName = suffixedUniName.c_str(); | 91 uniName = suffixedUniName.c_str(); |
86 } | 92 } |
87 if (kVoid_GrSLType != fUniType) { | 93 if (kVoid_GrSLType != fUniType) { |
88 fUni = builder->addUniform(GrGLShaderBuilder::kVertex_Visibility, | 94 fUni = builder->addUniform(GrGLShaderBuilder::kVertex_Visibility, |
89 fUniType, | 95 fUniType, |
90 uniName, | 96 uniName, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 192 } |
187 if (NULL != vsVaryingType) { | 193 if (NULL != vsVaryingType) { |
188 *vsVaryingType = varyingType; | 194 *vsVaryingType = varyingType; |
189 } | 195 } |
190 } | 196 } |
191 | 197 |
192 void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager, | 198 void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager, |
193 const SkMatrix& matrix, | 199 const SkMatrix& matrix, |
194 const GrDrawEffect& drawEffect, | 200 const GrDrawEffect& drawEffect, |
195 const GrTexture* texture) { | 201 const GrTexture* texture) { |
196 SkASSERT(fUni.isValid() != (kVoid_GrSLType == fUniType)); | 202 SkASSERT(fUni.isValid() != (fTexGenUnit >= 0 || kVoid_GrSLType == fUniType))
; |
197 const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsTy
pe ? | 203 const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsTy
pe ? |
198 drawEffect.getCoordChangeMatrix() : | 204 drawEffect.getCoordChangeMatrix() : |
199 SkMatrix::I(); | 205 SkMatrix::I(); |
200 switch (fUniType) { | 206 switch (fUniType) { |
201 case kVoid_GrSLType: | 207 case kVoid_GrSLType: |
202 SkASSERT(matrix.isIdentity()); | 208 SkASSERT(matrix.isIdentity()); |
203 SkASSERT(coordChangeMatrix.isIdentity()); | 209 SkASSERT(coordChangeMatrix.isIdentity()); |
204 SkASSERT(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); | 210 SkASSERT(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); |
| 211 if (fTexGenUnit >= 0) { |
| 212 SkASSERT(fNumTexGenComponents == 2); |
| 213 GrGLfloat texgenCoefficients[] = {1, 0, 0, |
| 214 0, 1, 0}; |
| 215 uniformManager.enableGlobalTexGen(fTexGenUnit, 2, texgenCoeffici
ents); |
| 216 } |
205 return; | 217 return; |
206 case kVec2f_GrSLType: { | 218 case kVec2f_GrSLType: { |
207 SkASSERT(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChang
eMatrix.getType())); | 219 SkASSERT(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChang
eMatrix.getType())); |
208 SkASSERT(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); | 220 SkASSERT(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->ori
gin()); |
209 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMat
rix::kMTransX]; | 221 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMat
rix::kMTransX]; |
210 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMat
rix::kMTransY]; | 222 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMat
rix::kMTransY]; |
211 if (fPrevMatrix.get(SkMatrix::kMTransX) != tx || | 223 if (fTexGenUnit >= 0) { |
212 fPrevMatrix.get(SkMatrix::kMTransY) != ty) { | 224 SkASSERT(fNumTexGenComponents == 2); |
| 225 GrGLfloat texgenCoefficients[] = {1, 0, SkScalarToFloat(tx), |
| 226 0, 1, SkScalarToFloat(ty)}; |
| 227 uniformManager.enableGlobalTexGen(fTexGenUnit, 2, texgenCoeffici
ents); |
| 228 } else if (fPrevMatrix.get(SkMatrix::kMTransX) != tx || |
| 229 fPrevMatrix.get(SkMatrix::kMTransY) != ty) { |
213 uniformManager.set2f(fUni, tx, ty); | 230 uniformManager.set2f(fUni, tx, ty); |
214 fPrevMatrix.set(SkMatrix::kMTransX, tx); | 231 fPrevMatrix.set(SkMatrix::kMTransX, tx); |
215 fPrevMatrix.set(SkMatrix::kMTransY, ty); | 232 fPrevMatrix.set(SkMatrix::kMTransY, ty); |
216 } | 233 } |
217 break; | 234 break; |
218 } | 235 } |
219 case kMat33f_GrSLType: { | 236 case kMat33f_GrSLType: { |
220 SkMatrix combined; | 237 SkMatrix combined; |
221 combined.setConcat(matrix, coordChangeMatrix); | 238 combined.setConcat(matrix, coordChangeMatrix); |
222 if (NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->origi
n()) { | 239 if (NULL != texture && kBottomLeft_GrSurfaceOrigin == texture->origi
n()) { |
223 // combined.postScale(1,-1); | 240 // combined.postScale(1,-1); |
224 // combined.postTranslate(0,1); | 241 // combined.postTranslate(0,1); |
225 combined.set(SkMatrix::kMSkewY, | 242 combined.set(SkMatrix::kMSkewY, |
226 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); | 243 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
227 combined.set(SkMatrix::kMScaleY, | 244 combined.set(SkMatrix::kMScaleY, |
228 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY])
; | 245 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY])
; |
229 combined.set(SkMatrix::kMTransY, | 246 combined.set(SkMatrix::kMTransY, |
230 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY])
; | 247 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY])
; |
231 } | 248 } |
232 if (!fPrevMatrix.cheapEqualTo(combined)) { | 249 if (fTexGenUnit >= 0) { |
| 250 uniformManager.enableGlobalTexGen(fTexGenUnit, fNumTexGenCompone
nts, combined); |
| 251 } else if (!fPrevMatrix.cheapEqualTo(combined)) { |
233 uniformManager.setSkMatrix(fUni, combined); | 252 uniformManager.setSkMatrix(fUni, combined); |
234 fPrevMatrix = combined; | 253 fPrevMatrix = combined; |
235 } | 254 } |
236 break; | 255 break; |
237 } | 256 } |
238 default: | 257 default: |
239 GrCrash("Unexpected uniform type."); | 258 GrCrash("Unexpected uniform type."); |
240 } | 259 } |
241 } | 260 } |
OLD | NEW |