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 "GrDrawState.h" | 8 #include "GrDrawState.h" |
9 #include "GrPaint.h" | 9 #include "GrPaint.h" |
10 | 10 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 fVertexAttribs.reset(); | 126 fVertexAttribs.reset(); |
127 fVertexAttribs.push_back(kPositionAttrib); | 127 fVertexAttribs.push_back(kPositionAttrib); |
128 | 128 |
129 fCommon.fAttribBindings = kDefault_AttribBindings; | 129 fCommon.fAttribBindings = kDefault_AttribBindings; |
130 | 130 |
131 fAttribIndices[kPosition_AttribIndex] = 0; | 131 fAttribIndices[kPosition_AttribIndex] = 0; |
132 } | 132 } |
133 | 133 |
134 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
135 | 135 |
| 136 bool GrDrawState::validateVertexAttribs() const { |
| 137 // color and coverage can set indices beyond the standard count |
| 138 static const int kMaxValidAttribIndex = kVertexAttribCnt+2; |
| 139 int attributeTypes[kMaxValidAttribIndex]; |
| 140 for (int i = 0; i < kMaxValidAttribIndex; ++i) { |
| 141 attributeTypes[i] = -1; |
| 142 } |
| 143 |
| 144 // sentinel to make sure effects don't try to use built-in attributes |
| 145 static const int kBuiltInAttributeType = 10000; |
| 146 |
| 147 // check our built-in indices |
| 148 if (fAttribIndices[kPosition_AttribIndex] >= kVertexAttribCnt) { |
| 149 return false; |
| 150 } |
| 151 attributeTypes[fAttribIndices[kPosition_AttribIndex]] = kBuiltInAttributeTyp
e; |
| 152 for (int j = kColor_AttribIndex; j <= kCoverage_AttribIndex; ++j) { |
| 153 if (fCommon.fAttribBindings & kAttribIndexMasks[j]) { |
| 154 int attributeIndex = fAttribIndices[j]; |
| 155 if (attributeIndex >= kMaxValidAttribIndex) { |
| 156 return false; |
| 157 } |
| 158 // they should not be shared at all |
| 159 if (attributeTypes[attributeIndex] != -1) { |
| 160 return false; |
| 161 } |
| 162 attributeTypes[attributeIndex] = kBuiltInAttributeType; |
| 163 } |
| 164 } |
| 165 for (int j = kEdge_AttribIndex; j < kAttribIndexCount; ++j) { |
| 166 if (fCommon.fAttribBindings & kAttribIndexMasks[j]) { |
| 167 int attributeIndex = fAttribIndices[j]; |
| 168 if (attributeIndex >= kVertexAttribCnt) { |
| 169 return false; |
| 170 } |
| 171 // they should not be shared at all |
| 172 if (attributeTypes[attributeIndex] != -1) { |
| 173 return false; |
| 174 } |
| 175 attributeTypes[attributeIndex] = kBuiltInAttributeType; |
| 176 } |
| 177 } |
| 178 |
| 179 // now those set by effects |
| 180 for (int s = 0; s < kNumStages; ++s) { |
| 181 const GrEffectStage& stage = fStages[s]; |
| 182 const GrEffectRef* effect = stage.getEffect(); |
| 183 if (effect == NULL) { |
| 184 continue; |
| 185 } |
| 186 |
| 187 // make sure that the count in the stage and the effect matches |
| 188 int numAttributes = stage.getVertexAttribIndexCount(); |
| 189 if (numAttributes != effect->get()->numVertexAttribs()) { |
| 190 return false; |
| 191 } |
| 192 |
| 193 // make sure that any shared indices have the same type |
| 194 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 195 for (int i = 0; i < numAttributes; ++i) { |
| 196 int attributeIndex = attributeIndices[i]; |
| 197 if (attributeIndex >= kVertexAttribCnt) { |
| 198 return false; |
| 199 } |
| 200 |
| 201 GrSLType attributeType = effect->get()->vertexAttribType(i); |
| 202 if (attributeTypes[attributeIndex] != -1 && |
| 203 attributeTypes[attributeIndex] != attributeType) { |
| 204 return false; |
| 205 } |
| 206 attributeTypes[attributeIndex] = attributeType; |
| 207 } |
| 208 } |
| 209 |
| 210 return true; |
| 211 } |
| 212 |
| 213 //////////////////////////////////////////////////////////////////////////////// |
| 214 |
136 bool GrDrawState::AttributesBindExplicitTexCoords(GrAttribBindings attribBinding
s) { | 215 bool GrDrawState::AttributesBindExplicitTexCoords(GrAttribBindings attribBinding
s) { |
137 return SkToBool(kTexCoord_AttribBindingsMask & attribBindings); | 216 return SkToBool(kTexCoord_AttribBindingsMask & attribBindings); |
138 } | 217 } |
139 | 218 |
140 //////////////////////////////////////////////////////////////////////////////// | 219 //////////////////////////////////////////////////////////////////////////////// |
141 | 220 |
142 void GrDrawState::VertexAttributesUnitTest() { | 221 void GrDrawState::VertexAttributesUnitTest() { |
143 // Ensure that our tex coord mask is correct | 222 // Ensure that our tex coord mask is correct |
144 GrAttribBindings texCoordMask; | 223 GrAttribBindings texCoordMask; |
145 gen_tex_coord_mask(&texCoordMask); | 224 gen_tex_coord_mask(&texCoordMask); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 } | 562 } |
484 fRestoreMask |= (1 << s); | 563 fRestoreMask |= (1 << s); |
485 GrEffectStage* stage = drawState->fStages + s; | 564 GrEffectStage* stage = drawState->fStages + s; |
486 stage->saveCoordChange(&fSavedCoordChanges[s]); | 565 stage->saveCoordChange(&fSavedCoordChanges[s]); |
487 stage->preConcatCoordChange(invVM); | 566 stage->preConcatCoordChange(invVM); |
488 } | 567 } |
489 } | 568 } |
490 drawState->viewMatrix()->reset(); | 569 drawState->viewMatrix()->reset(); |
491 return true; | 570 return true; |
492 } | 571 } |
OLD | NEW |