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 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder(
); |
| 52 SkASSERT(NULL != vertexBuilder); |
| 53 |
51 GrSLType varyingType = kVoid_GrSLType; | 54 GrSLType varyingType = kVoid_GrSLType; |
52 const char* uniName; | 55 const char* uniName; |
53 key &= kKeyMask; | 56 key &= kKeyMask; |
54 switch (key & kMatrixTypeKeyMask) { | 57 switch (key & kMatrixTypeKeyMask) { |
55 case kIdentity_MatrixType: | 58 case kIdentity_MatrixType: |
56 fUniType = kVoid_GrSLType; | 59 fUniType = kVoid_GrSLType; |
57 varyingType = kVec2f_GrSLType; | 60 varyingType = kVec2f_GrSLType; |
58 break; | 61 break; |
59 case kTrans_MatrixType: | 62 case kTrans_MatrixType: |
60 fUniType = kVec2f_GrSLType; | 63 fUniType = kVec2f_GrSLType; |
(...skipping 28 matching lines...) Expand all Loading... |
89 | 92 |
90 const char* varyingName = "MatrixCoord"; | 93 const char* varyingName = "MatrixCoord"; |
91 SkString suffixedVaryingName; | 94 SkString suffixedVaryingName; |
92 if (NULL != suffix) { | 95 if (NULL != suffix) { |
93 suffixedVaryingName.append(varyingName); | 96 suffixedVaryingName.append(varyingName); |
94 suffixedVaryingName.append(suffix); | 97 suffixedVaryingName.append(suffix); |
95 varyingName = suffixedVaryingName.c_str(); | 98 varyingName = suffixedVaryingName.c_str(); |
96 } | 99 } |
97 const char* vsVaryingName; | 100 const char* vsVaryingName; |
98 const char* fsVaryingName; | 101 const char* fsVaryingName; |
99 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingName
); | 102 vertexBuilder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryi
ngName); |
100 | 103 |
101 const GrGLShaderVar* coords; | 104 const GrGLShaderVar* coords; |
102 switch (fCoordsType) { | 105 switch (fCoordsType) { |
103 case GrEffect::kLocal_CoordsType: | 106 case GrEffect::kLocal_CoordsType: |
104 SkASSERT(!(kPositionCoords_Flag & key)); | 107 SkASSERT(!(kPositionCoords_Flag & key)); |
105 coords = &builder->localCoordsAttribute(); | 108 coords = &vertexBuilder->localCoordsAttribute(); |
106 break; | 109 break; |
107 case GrEffect::kPosition_CoordsType: | 110 case GrEffect::kPosition_CoordsType: |
108 SkASSERT((kPositionCoords_Flag & key) || !builder->hasExplicitLocalC
oords()); | 111 SkASSERT((kPositionCoords_Flag & key) || !vertexBuilder->hasExplicit
LocalCoords()); |
109 coords = &builder->positionAttribute(); | 112 coords = &vertexBuilder->positionAttribute(); |
110 break; | 113 break; |
111 default: | 114 default: |
112 coords = NULL; // prevents warning | 115 coords = NULL; // prevents warning |
113 GrCrash("Unexpected coords type."); | 116 GrCrash("Unexpected coords type."); |
114 } | 117 } |
115 // varying = matrix * coords (logically) | 118 // varying = matrix * coords (logically) |
116 switch (fUniType) { | 119 switch (fUniType) { |
117 case kVoid_GrSLType: | 120 case kVoid_GrSLType: |
118 SkASSERT(kVec2f_GrSLType == varyingType); | 121 SkASSERT(kVec2f_GrSLType == varyingType); |
119 builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords->c_str(
)); | 122 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords->
c_str()); |
120 break; | 123 break; |
121 case kVec2f_GrSLType: | 124 case kVec2f_GrSLType: |
122 SkASSERT(kVec2f_GrSLType == varyingType); | 125 SkASSERT(kVec2f_GrSLType == varyingType); |
123 builder->vsCodeAppendf("\t%s = %s + %s;\n", | 126 vertexBuilder->vsCodeAppendf("\t%s = %s + %s;\n", |
124 vsVaryingName, uniName, coords->c_str()); | 127 vsVaryingName, uniName, coords->c_str()
); |
125 break; | 128 break; |
126 case kMat33f_GrSLType: { | 129 case kMat33f_GrSLType: { |
127 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); | 130 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyin
gType); |
128 if (kVec2f_GrSLType == varyingType) { | 131 if (kVec2f_GrSLType == varyingType) { |
129 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", | 132 vertexBuilder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", |
130 vsVaryingName, uniName, coords->c_str()); | 133 vsVaryingName, uniName, coords->c_s
tr()); |
131 } else { | 134 } else { |
132 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", | 135 vertexBuilder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", |
133 vsVaryingName, uniName, coords->c_str()); | 136 vsVaryingName, uniName, coords->c_s
tr()); |
134 } | 137 } |
135 break; | 138 break; |
136 } | 139 } |
137 default: | 140 default: |
138 GrCrash("Unexpected uniform type."); | 141 GrCrash("Unexpected uniform type."); |
139 } | 142 } |
140 if (NULL != vsCoordName) { | 143 if (NULL != vsCoordName) { |
141 *vsCoordName = vsVaryingName; | 144 *vsCoordName = vsVaryingName; |
142 } | 145 } |
143 if (NULL != fsCoordName) { | 146 if (NULL != fsCoordName) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (!fPrevMatrix.cheapEqualTo(combined)) { | 231 if (!fPrevMatrix.cheapEqualTo(combined)) { |
229 uniformManager.setSkMatrix(fUni, combined); | 232 uniformManager.setSkMatrix(fUni, combined); |
230 fPrevMatrix = combined; | 233 fPrevMatrix = combined; |
231 } | 234 } |
232 break; | 235 break; |
233 } | 236 } |
234 default: | 237 default: |
235 GrCrash("Unexpected uniform type."); | 238 GrCrash("Unexpected uniform type."); |
236 } | 239 } |
237 } | 240 } |
OLD | NEW |