Vertex Attrib configurations now handled as pointers vs. SkSTArrays
https://codereview.chromium.org/14328009/
git-svn-id: http://skia.googlecode.com/svn/trunk@8787 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 85c241a..2a6e20a 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -322,6 +322,16 @@
}
}
+namespace {
+
+// position + local coordinate
+extern const GrVertexAttrib gVertexAttribs[] = {
+ {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
+ {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBinding}
+};
+
+};
+
// The desired texture is NPOT and tiled but that isn't supported by
// the current hardware. Resize the texture to be a POT
GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc,
@@ -358,12 +368,7 @@
GrTextureParams params(SkShader::kClamp_TileMode, needsFiltering);
drawState->createTextureEffect(0, clampedTexture, SkMatrix::I(), params);
- // position + local coordinate
- static const GrVertexAttrib kVertexAttribs[] = {
- {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
- {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBinding}
- };
- drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
+ drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttribs));
GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
@@ -870,6 +875,44 @@
target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
}
+namespace {
+
+extern const GrVertexAttrib gPosUVColorAttribs[] = {
+ {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
+ {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBinding },
+ {kVec4ub_GrVertexAttribType, 2*sizeof(GrPoint), kColor_GrVertexAttribBinding}
+};
+
+extern const GrVertexAttrib gPosColorAttribs[] = {
+ {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding},
+ {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding},
+};
+
+static void set_vertex_attributes(GrDrawState* drawState,
+ const GrPoint* texCoords,
+ const GrColor* colors,
+ int* colorOffset,
+ int* texOffset) {
+ *texOffset = -1;
+ *colorOffset = -1;
+
+ if (NULL != texCoords && NULL != colors) {
+ *texOffset = sizeof(GrPoint);
+ *colorOffset = 2*sizeof(GrPoint);
+ drawState->setVertexAttribs<gPosUVColorAttribs>(3);
+ } else if (NULL != texCoords) {
+ *texOffset = sizeof(GrPoint);
+ drawState->setVertexAttribs<gPosUVColorAttribs>(2);
+ } else if (NULL != colors) {
+ *colorOffset = sizeof(GrPoint);
+ drawState->setVertexAttribs<gPosColorAttribs>(2);
+ } else {
+ drawState->setVertexAttribs<gPosColorAttribs>(1);
+ }
+}
+
+};
+
void GrContext::drawVertices(const GrPaint& paint,
GrPrimitiveType primitiveType,
int vertexCount,
@@ -887,36 +930,10 @@
GrDrawState* drawState = target->drawState();
- GrVertexAttribArray<3> attribs;
- size_t currentOffset = 0;
int colorOffset = -1, texOffset = -1;
-
- // set position attribute
- GrVertexAttrib currAttrib =
- {kVec2f_GrVertexAttribType, currentOffset, kPosition_GrVertexAttribBinding};
- attribs.push_back(currAttrib);
- currentOffset += sizeof(GrPoint);
-
- // set up optional texture coordinate attributes
- if (NULL != texCoords) {
- currAttrib.set(kVec2f_GrVertexAttribType, currentOffset, kLocalCoord_GrVertexAttribBinding);
- attribs.push_back(currAttrib);
- texOffset = currentOffset;
- currentOffset += sizeof(GrPoint);
- }
-
- // set up optional color attributes
- if (NULL != colors) {
- currAttrib.set(kVec4ub_GrVertexAttribType, currentOffset, kColor_GrVertexAttribBinding);
- attribs.push_back(currAttrib);
- colorOffset = currentOffset;
- currentOffset += sizeof(GrColor);
- }
-
- drawState->setVertexAttribs(attribs.begin(), attribs.count());
+ set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset);
size_t vertexSize = drawState->getVertexSize();
- GrAssert(vertexSize == currentOffset);
if (sizeof(GrPoint) != vertexSize) {
if (!geo.set(target, vertexCount, 0)) {
GrPrintf("Failed to get space for vertices!\n");