| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 uint32_t mask = (1 << dwordCount)-1; | 61 uint32_t mask = (1 << dwordCount)-1; |
| 62 size_t offsetShift = attribs[index].fOffset >> 2; | 62 size_t offsetShift = attribs[index].fOffset >> 2; |
| 63 GrAssert(!(overlapCheck & (mask << offsetShift))); | 63 GrAssert(!(overlapCheck & (mask << offsetShift))); |
| 64 overlapCheck |= (mask << offsetShift); | 64 overlapCheck |= (mask << offsetShift); |
| 65 #endif | 65 #endif |
| 66 } | 66 } |
| 67 return size; | 67 return size; |
| 68 } | 68 } |
| 69 | 69 |
| 70 size_t GrDrawState::getVertexSize() const { | 70 size_t GrDrawState::getVertexSize() const { |
| 71 return vertex_size(fCommon.fVertexAttribs.begin(), fCommon.fVertexAttribs.co
unt()); | 71 return vertex_size(fCommon.fVAPtr, fCommon.fVACount); |
| 72 } | 72 } |
| 73 | 73 |
| 74 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
| 75 | 75 |
| 76 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { | 76 void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) { |
| 77 GrAssert(count <= kMaxVertexAttribCnt); | 77 GrAssert(count <= kMaxVertexAttribCnt); |
| 78 fCommon.fVertexAttribs.reset(attribs, count); | 78 |
| 79 fCommon.fVAPtr = attribs; |
| 80 fCommon.fVACount = count; |
| 79 | 81 |
| 80 // Set all the indices to -1 | 82 // Set all the indices to -1 |
| 81 memset(fCommon.fFixedFunctionVertexAttribIndices, | 83 memset(fCommon.fFixedFunctionVertexAttribIndices, |
| 82 0xff, | 84 0xff, |
| 83 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); | 85 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); |
| 84 #if GR_DEBUG | 86 #if GR_DEBUG |
| 85 uint32_t overlapCheck = 0; | 87 uint32_t overlapCheck = 0; |
| 86 #endif | 88 #endif |
| 87 for (int i = 0; i < count; ++i) { | 89 for (int i = 0; i < count; ++i) { |
| 88 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { | 90 if (attribs[i].fBinding < kGrFixedFunctionVertexAttribBindingCnt) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 102 } | 104 } |
| 103 // Positions must be specified. | 105 // Positions must be specified. |
| 104 GrAssert(-1 != fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexA
ttribBinding]); | 106 GrAssert(-1 != fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexA
ttribBinding]); |
| 105 } | 107 } |
| 106 | 108 |
| 107 //////////////////////////////////////////////////////////////////////////////// | 109 //////////////////////////////////////////////////////////////////////////////// |
| 108 | 110 |
| 109 void GrDrawState::setDefaultVertexAttribs() { | 111 void GrDrawState::setDefaultVertexAttribs() { |
| 110 static const GrVertexAttrib kPositionAttrib = | 112 static const GrVertexAttrib kPositionAttrib = |
| 111 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; | 113 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}; |
| 112 fCommon.fVertexAttribs.reset(&kPositionAttrib, 1); | 114 |
| 115 fCommon.fVAPtr = &kPositionAttrib; |
| 116 fCommon.fVACount = 1; |
| 117 |
| 113 // set all the fixed function indices to -1 except position. | 118 // set all the fixed function indices to -1 except position. |
| 114 memset(fCommon.fFixedFunctionVertexAttribIndices, | 119 memset(fCommon.fFixedFunctionVertexAttribIndices, |
| 115 0xff, | 120 0xff, |
| 116 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); | 121 sizeof(fCommon.fFixedFunctionVertexAttribIndices)); |
| 117 fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] =
0; | 122 fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] =
0; |
| 118 } | 123 } |
| 119 | 124 |
| 120 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
| 121 | 126 |
| 122 bool GrDrawState::validateVertexAttribs() const { | 127 bool GrDrawState::validateVertexAttribs() const { |
| 123 // check consistency of effects and attributes | 128 // check consistency of effects and attributes |
| 124 GrSLType slTypes[kMaxVertexAttribCnt]; | 129 GrSLType slTypes[kMaxVertexAttribCnt]; |
| 125 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { | 130 for (int i = 0; i < kMaxVertexAttribCnt; ++i) { |
| 126 slTypes[i] = static_cast<GrSLType>(-1); | 131 slTypes[i] = static_cast<GrSLType>(-1); |
| 127 } | 132 } |
| 128 for (int s = 0; s < kNumStages; ++s) { | 133 for (int s = 0; s < kNumStages; ++s) { |
| 129 if (this->isStageEnabled(s)) { | 134 if (this->isStageEnabled(s)) { |
| 130 const GrEffectStage& stage = fStages[s]; | 135 const GrEffectStage& stage = fStages[s]; |
| 131 const GrEffectRef* effect = stage.getEffect(); | 136 const GrEffectRef* effect = stage.getEffect(); |
| 132 // make sure that any attribute indices have the correct binding typ
e, that the attrib | 137 // make sure that any attribute indices have the correct binding typ
e, that the attrib |
| 133 // type and effect's shader lang type are compatible, and that attri
butes shared by | 138 // type and effect's shader lang type are compatible, and that attri
butes shared by |
| 134 // multiple effects use the same shader lang type. | 139 // multiple effects use the same shader lang type. |
| 135 const int* attributeIndices = stage.getVertexAttribIndices(); | 140 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 136 int numAttributes = stage.getVertexAttribIndexCount(); | 141 int numAttributes = stage.getVertexAttribIndexCount(); |
| 137 for (int i = 0; i < numAttributes; ++i) { | 142 for (int i = 0; i < numAttributes; ++i) { |
| 138 int attribIndex = attributeIndices[i]; | 143 int attribIndex = attributeIndices[i]; |
| 139 if (attribIndex >= fCommon.fVertexAttribs.count() || | 144 if (attribIndex >= fCommon.fVACount || |
| 140 kEffect_GrVertexAttribBinding != fCommon.fVertexAttribs[attr
ibIndex].fBinding) { | 145 kEffect_GrVertexAttribBinding != fCommon.fVAPtr[attribIndex]
.fBinding) { |
| 141 return false; | 146 return false; |
| 142 } | 147 } |
| 143 | 148 |
| 144 GrSLType effectSLType = (*effect)->vertexAttribType(i); | 149 GrSLType effectSLType = (*effect)->vertexAttribType(i); |
| 145 GrVertexAttribType attribType = fCommon.fVertexAttribs[attribInd
ex].fType; | 150 GrVertexAttribType attribType = fCommon.fVAPtr[attribIndex].fTyp
e; |
| 146 int slVecCount = GrSLTypeVectorCount(effectSLType); | 151 int slVecCount = GrSLTypeVectorCount(effectSLType); |
| 147 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); | 152 int attribVecCount = GrVertexAttribTypeVectorCount(attribType); |
| 148 if (slVecCount != attribVecCount || | 153 if (slVecCount != attribVecCount || |
| 149 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && | 154 (static_cast<GrSLType>(-1) != slTypes[attribIndex] && |
| 150 slTypes[attribIndex] != effectSLType)) { | 155 slTypes[attribIndex] != effectSLType)) { |
| 151 return false; | 156 return false; |
| 152 } | 157 } |
| 153 slTypes[attribIndex] = effectSLType; | 158 slTypes[attribIndex] = effectSLType; |
| 154 } | 159 } |
| 155 } | 160 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 439 } |
| 435 fRestoreMask |= (1 << s); | 440 fRestoreMask |= (1 << s); |
| 436 GrEffectStage* stage = drawState->fStages + s; | 441 GrEffectStage* stage = drawState->fStages + s; |
| 437 stage->saveCoordChange(&fSavedCoordChanges[s]); | 442 stage->saveCoordChange(&fSavedCoordChanges[s]); |
| 438 stage->localCoordChange(invVM); | 443 stage->localCoordChange(invVM); |
| 439 } | 444 } |
| 440 } | 445 } |
| 441 drawState->viewMatrix()->reset(); | 446 drawState->viewMatrix()->reset(); |
| 442 return true; | 447 return true; |
| 443 } | 448 } |
| OLD | NEW |