OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #ifndef GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED |
9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED |
10 | 10 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 size_t getVertexSize() const; | 175 size_t getVertexSize() const; |
176 | 176 |
177 /** | 177 /** |
178 * Sets default vertex attributes for next draw. | 178 * Sets default vertex attributes for next draw. |
179 * | 179 * |
180 * This will also set default vertex attribute indices and bindings | 180 * This will also set default vertex attribute indices and bindings |
181 */ | 181 */ |
182 void setDefaultVertexAttribs(); | 182 void setDefaultVertexAttribs(); |
183 | 183 |
| 184 bool validateVertexAttribs() const; |
| 185 |
184 //////////////////////////////////////////////////////////////////////////// | 186 //////////////////////////////////////////////////////////////////////////// |
185 // Helpers for picking apart vertex attributes | 187 // Helpers for picking apart vertex attributes |
186 | 188 |
187 // helper array to let us check the expected so we know what bound attrib in
dices | 189 // helper array to let us check the expected so we know what bound attrib in
dices |
188 // we care about | 190 // we care about |
189 static const size_t kVertexAttribSizes[kGrVertexAttribTypeCount]; | 191 static const size_t kVertexAttribSizes[kGrVertexAttribTypeCount]; |
190 | 192 |
191 /** | 193 /** |
192 * Accessing positions, texture coords, or colors, of a vertex within an | 194 * Accessing positions, texture coords, or colors, of a vertex within an |
193 * array is a hassle involving casts and simple math. These helpers exist | 195 * array is a hassle involving casts and simple math. These helpers exist |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 * Determines whether src alpha is guaranteed to be one for all src pixels | 327 * Determines whether src alpha is guaranteed to be one for all src pixels |
326 */ | 328 */ |
327 bool srcAlphaWillBeOne(GrAttribBindings) const; | 329 bool srcAlphaWillBeOne(GrAttribBindings) const; |
328 | 330 |
329 /** | 331 /** |
330 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. | 332 * Determines whether the output coverage is guaranteed to be one for all pi
xels hit by a draw. |
331 */ | 333 */ |
332 bool hasSolidCoverage(GrAttribBindings) const; | 334 bool hasSolidCoverage(GrAttribBindings) const; |
333 | 335 |
334 static void VertexAttributesUnitTest(); | 336 static void VertexAttributesUnitTest(); |
335 | 337 |
336 /// @} | 338 /// @} |
337 | 339 |
338 /////////////////////////////////////////////////////////////////////////// | 340 /////////////////////////////////////////////////////////////////////////// |
339 /// @name Vertex Attribute Indices | 341 /// @name Vertex Attribute Indices |
340 //// | 342 //// |
341 | 343 |
342 /** | 344 /** |
343 * Vertex attribute indices map the data set in the vertex attribute array | 345 * Vertex attribute indices map the data set in the vertex attribute array |
344 * to the bindings specified in the attribute bindings. Each binding type | 346 * to the bindings specified in the attribute bindings. Each binding type |
345 * has an associated index in the attribute array. This index is used to | 347 * has an associated index in the attribute array. This index is used to |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 GrColor getCoverage() const { | 478 GrColor getCoverage() const { |
477 return fCommon.fCoverage; | 479 return fCommon.fCoverage; |
478 } | 480 } |
479 | 481 |
480 /// @} | 482 /// @} |
481 | 483 |
482 /////////////////////////////////////////////////////////////////////////// | 484 /////////////////////////////////////////////////////////////////////////// |
483 /// @name Effect Stages | 485 /// @name Effect Stages |
484 //// | 486 //// |
485 | 487 |
486 const GrEffectRef* setEffect(int stageIdx, const GrEffectRef* effect) { | 488 const GrEffectRef* setEffect(int stageIdx, const GrEffectRef* effect, |
487 fStages[stageIdx].setEffect(effect); | 489 const int* indices = NULL) { |
| 490 fStages[stageIdx].setEffect(effect, indices); |
488 return effect; | 491 return effect; |
489 } | 492 } |
490 | 493 |
491 /** | 494 /** |
492 * Creates a GrSimpleTextureEffect. | 495 * Creates a GrSimpleTextureEffect. |
493 */ | 496 */ |
494 void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& m
atrix) { | 497 void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& m
atrix) { |
495 GrAssert(!this->getStage(stageIdx).getEffect()); | 498 GrAssert(!this->getStage(stageIdx).getEffect()); |
496 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); | 499 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); |
497 this->setEffect(stageIdx, effect)->unref(); | 500 this->setEffect(stageIdx, effect)->unref(); |
498 } | 501 } |
499 void createTextureEffect(int stageIdx, | 502 void createTextureEffect(int stageIdx, |
500 GrTexture* texture, | 503 GrTexture* texture, |
501 const SkMatrix& matrix, | 504 const SkMatrix& matrix, |
502 const GrTextureParams& params) { | 505 const GrTextureParams& params) { |
503 GrAssert(!this->getStage(stageIdx).getEffect()); | 506 GrAssert(!this->getStage(stageIdx).getEffect()); |
504 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, par
ams); | 507 GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, par
ams); |
505 this->setEffect(stageIdx, effect)->unref(); | 508 this->setEffect(stageIdx, effect)->unref(); |
506 } | 509 } |
507 | 510 |
508 bool stagesDisabled() { | 511 bool stagesDisabled() { |
509 for (int i = 0; i < kNumStages; ++i) { | 512 for (int i = 0; i < kNumStages; ++i) { |
510 if (NULL != fStages[i].getEffect()) { | 513 if (NULL != fStages[i].getEffect()) { |
511 return false; | 514 return false; |
512 } | 515 } |
513 } | 516 } |
514 return true; | 517 return true; |
515 } | 518 } |
516 | 519 |
517 void disableStage(int stageIdx) { this->setEffect(stageIdx, NULL); } | 520 void disableStage(int stageIdx) { |
| 521 this->setEffect(stageIdx, NULL, NULL); |
| 522 } |
518 | 523 |
519 /** | 524 /** |
520 * Release all the GrEffects referred to by this draw state. | 525 * Release all the GrEffects referred to by this draw state. |
521 */ | 526 */ |
522 void disableStages() { | 527 void disableStages() { |
523 for (int i = 0; i < kNumStages; ++i) { | 528 for (int i = 0; i < kNumStages; ++i) { |
524 this->disableStage(i); | 529 this->disableStage(i); |
525 } | 530 } |
526 } | 531 } |
527 | 532 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 components used). Coverage based on signed distance with negative | 1019 components used). Coverage based on signed distance with negative |
1015 being inside, positive outside. Edge specified in window space | 1020 being inside, positive outside. Edge specified in window space |
1016 (y-down) */ | 1021 (y-down) */ |
1017 kQuad_EdgeType, | 1022 kQuad_EdgeType, |
1018 /* Same as above but for hairline quadratics. Uses unsigned distance. | 1023 /* Same as above but for hairline quadratics. Uses unsigned distance. |
1019 Coverage is min(0, 1-distance). */ | 1024 Coverage is min(0, 1-distance). */ |
1020 kHairQuad_EdgeType, | 1025 kHairQuad_EdgeType, |
1021 /* Circle specified as center_x, center_y, outer_radius, inner_radius | 1026 /* Circle specified as center_x, center_y, outer_radius, inner_radius |
1022 all in window space (y-down). */ | 1027 all in window space (y-down). */ |
1023 kCircle_EdgeType, | 1028 kCircle_EdgeType, |
1024 /* Axis-aligned ellipse specified as center_x, center_y, x_radius, x_rad
ius/y_radius | |
1025 all in window space (y-down). */ | |
1026 kEllipse_EdgeType, | |
1027 | 1029 |
1028 kVertexEdgeTypeCnt | 1030 kVertexEdgeTypeCnt |
1029 }; | 1031 }; |
1030 | 1032 |
1031 /** | 1033 /** |
1032 * Determines the interpretation per-vertex edge data when the | 1034 * Determines the interpretation per-vertex edge data when the |
1033 * kEdge_AttribBindingsBit is set (see GrDrawTarget). When per-vertex edges | 1035 * kEdge_AttribBindingsBit is set (see GrDrawTarget). When per-vertex edges |
1034 * are not specified the value of this setting has no effect. | 1036 * are not specified the value of this setting has no effect. |
1035 */ | 1037 */ |
1036 void setVertexEdgeType(VertexEdgeType type) { | 1038 void setVertexEdgeType(VertexEdgeType type) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 | 1184 |
1183 bool isStageEnabled(int s) const { | 1185 bool isStageEnabled(int s) const { |
1184 GrAssert((unsigned)s < kNumStages); | 1186 GrAssert((unsigned)s < kNumStages); |
1185 return (NULL != fStages[s].getEffect()); | 1187 return (NULL != fStages[s].getEffect()); |
1186 } | 1188 } |
1187 | 1189 |
1188 bool operator ==(const GrDrawState& s) const { | 1190 bool operator ==(const GrDrawState& s) const { |
1189 if (fRenderTarget.get() != s.fRenderTarget.get() || fCommon != s.fCommon
) { | 1191 if (fRenderTarget.get() != s.fRenderTarget.get() || fCommon != s.fCommon
) { |
1190 return false; | 1192 return false; |
1191 } | 1193 } |
1192 if (fVertexAttribs.count() != s.fVertexAttribs.count()) { | 1194 if (fVertexAttribs != s.fVertexAttribs) { |
1193 return false; | 1195 return false; |
1194 } | 1196 } |
1195 for (int i = 0; i < fVertexAttribs.count(); ++i) { | |
1196 if (fVertexAttribs[i] != s.fVertexAttribs[i]) { | |
1197 return false; | |
1198 } | |
1199 } | |
1200 for (int i = 0; i < kAttribIndexCount; ++i) { | 1197 for (int i = 0; i < kAttribIndexCount; ++i) { |
1201 if ((i == kPosition_AttribIndex || | 1198 if ((i == kPosition_AttribIndex || |
1202 s.fCommon.fAttribBindings & kAttribIndexMasks[i]) && | 1199 s.fCommon.fAttribBindings & kAttribIndexMasks[i]) && |
1203 fAttribIndices[i] != s.fAttribIndices[i]) { | 1200 fAttribIndices[i] != s.fAttribIndices[i]) { |
1204 return false; | 1201 return false; |
1205 } | 1202 } |
1206 } | 1203 } |
1207 for (int i = 0; i < kNumStages; i++) { | 1204 for (int i = 0; i < kNumStages; i++) { |
1208 bool enabled = this->isStageEnabled(i); | 1205 bool enabled = this->isStageEnabled(i); |
1209 if (enabled != s.isStageEnabled(i)) { | 1206 if (enabled != s.isStageEnabled(i)) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 if (fRenderTarget != state.fRenderTarget.get() || fCommon != state.f
Common) { | 1325 if (fRenderTarget != state.fRenderTarget.get() || fCommon != state.f
Common) { |
1329 return false; | 1326 return false; |
1330 } | 1327 } |
1331 for (int i = 0; i < kAttribIndexCount; ++i) { | 1328 for (int i = 0; i < kAttribIndexCount; ++i) { |
1332 if ((i == kPosition_AttribIndex || | 1329 if ((i == kPosition_AttribIndex || |
1333 state.fCommon.fAttribBindings & kAttribIndexMasks[i]) && | 1330 state.fCommon.fAttribBindings & kAttribIndexMasks[i]) && |
1334 fAttribIndices[i] != state.fAttribIndices[i]) { | 1331 fAttribIndices[i] != state.fAttribIndices[i]) { |
1335 return false; | 1332 return false; |
1336 } | 1333 } |
1337 } | 1334 } |
1338 if (fVertexAttribs.count() != state.fVertexAttribs.count()) { | 1335 if (fVertexAttribs != state.fVertexAttribs) { |
1339 return false; | 1336 return false; |
1340 } | 1337 } |
1341 for (int i = 0; i < fVertexAttribs.count(); ++i) | |
1342 if (fVertexAttribs[i] != state.fVertexAttribs[i]) { | |
1343 return false; | |
1344 } | |
1345 for (int i = 0; i < kNumStages; ++i) { | 1338 for (int i = 0; i < kNumStages; ++i) { |
1346 if (!fStages[i].isEqual(state.fStages[i])) { | 1339 if (!fStages[i].isEqual(state.fStages[i])) { |
1347 return false; | 1340 return false; |
1348 } | 1341 } |
1349 } | 1342 } |
1350 return true; | 1343 return true; |
1351 } | 1344 } |
1352 | 1345 |
1353 private: | 1346 private: |
1354 GrRenderTarget* fRenderTarget; | 1347 GrRenderTarget* fRenderTarget; |
(...skipping 15 matching lines...) Expand all Loading... |
1370 int fAttribIndices[kAttribIndexCount]; | 1363 int fAttribIndices[kAttribIndexCount]; |
1371 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs; | 1364 GrVertexAttribArray<kVertexAttribCnt> fVertexAttribs; |
1372 GrEffectStage fStages[kNumStages]; | 1365 GrEffectStage fStages[kNumStages]; |
1373 | 1366 |
1374 typedef GrRefCnt INHERITED; | 1367 typedef GrRefCnt INHERITED; |
1375 }; | 1368 }; |
1376 | 1369 |
1377 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 1370 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
1378 | 1371 |
1379 #endif | 1372 #endif |
OLD | NEW |