aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrDrawState.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-12 12:26:08 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-12 12:26:08 +0000
commitff6ea2663f76aa85ec55ddd0f00ca7906f1bc4e3 (patch)
tree54941da56d3d90540bb21bfab8ca11f0504951e9 /src/gpu/GrDrawState.cpp
parent2e71f1619d9a2c51c1292e618f42a56ad2da1de8 (diff)
Add GrEllipseEdgeEffect.
Adds the effect that replaces the old oval rendering code. Also hooks in code to set attribute names and indices for effects. Author: jvanverth@google.com Review URL: https://chromiumcodereview.appspot.com/12462008 git-svn-id: http://skia.googlecode.com/svn/trunk@8092 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrDrawState.cpp')
-rw-r--r--src/gpu/GrDrawState.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index e797546118..fddce41099 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -133,6 +133,85 @@ void GrDrawState::setDefaultVertexAttribs() {
////////////////////////////////////////////////////////////////////////////////
+bool GrDrawState::validateVertexAttribs() const {
+ // color and coverage can set indices beyond the standard count
+ static const int kMaxValidAttribIndex = kVertexAttribCnt+2;
+ int attributeTypes[kMaxValidAttribIndex];
+ for (int i = 0; i < kMaxValidAttribIndex; ++i) {
+ attributeTypes[i] = -1;
+ }
+
+ // sentinel to make sure effects don't try to use built-in attributes
+ static const int kBuiltInAttributeType = 10000;
+
+ // check our built-in indices
+ if (fAttribIndices[kPosition_AttribIndex] >= kVertexAttribCnt) {
+ return false;
+ }
+ attributeTypes[fAttribIndices[kPosition_AttribIndex]] = kBuiltInAttributeType;
+ for (int j = kColor_AttribIndex; j <= kCoverage_AttribIndex; ++j) {
+ if (fCommon.fAttribBindings & kAttribIndexMasks[j]) {
+ int attributeIndex = fAttribIndices[j];
+ if (attributeIndex >= kMaxValidAttribIndex) {
+ return false;
+ }
+ // they should not be shared at all
+ if (attributeTypes[attributeIndex] != -1) {
+ return false;
+ }
+ attributeTypes[attributeIndex] = kBuiltInAttributeType;
+ }
+ }
+ for (int j = kEdge_AttribIndex; j < kAttribIndexCount; ++j) {
+ if (fCommon.fAttribBindings & kAttribIndexMasks[j]) {
+ int attributeIndex = fAttribIndices[j];
+ if (attributeIndex >= kVertexAttribCnt) {
+ return false;
+ }
+ // they should not be shared at all
+ if (attributeTypes[attributeIndex] != -1) {
+ return false;
+ }
+ attributeTypes[attributeIndex] = kBuiltInAttributeType;
+ }
+ }
+
+ // now those set by effects
+ for (int s = 0; s < kNumStages; ++s) {
+ const GrEffectStage& stage = fStages[s];
+ const GrEffectRef* effect = stage.getEffect();
+ if (effect == NULL) {
+ continue;
+ }
+
+ // make sure that the count in the stage and the effect matches
+ int numAttributes = stage.getVertexAttribIndexCount();
+ if (numAttributes != effect->get()->numVertexAttribs()) {
+ return false;
+ }
+
+ // make sure that any shared indices have the same type
+ const int* attributeIndices = stage.getVertexAttribIndices();
+ for (int i = 0; i < numAttributes; ++i) {
+ int attributeIndex = attributeIndices[i];
+ if (attributeIndex >= kVertexAttribCnt) {
+ return false;
+ }
+
+ GrSLType attributeType = effect->get()->vertexAttribType(i);
+ if (attributeTypes[attributeIndex] != -1 &&
+ attributeTypes[attributeIndex] != attributeType) {
+ return false;
+ }
+ attributeTypes[attributeIndex] = attributeType;
+ }
+ }
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
bool GrDrawState::AttributesBindExplicitTexCoords(GrAttribBindings attribBindings) {
return SkToBool(kTexCoord_AttribBindingsMask & attribBindings);
}