Index: src/gpu/GrContext.cpp |
=================================================================== |
--- src/gpu/GrContext.cpp (revision 8777) |
+++ src/gpu/GrContext.cpp (working copy) |
@@ -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); |
@@ -932,6 +937,44 @@ |
#endif |
} |
+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, |
@@ -949,36 +992,10 @@ |
GrDrawState* drawState = target->drawState(); |
- GrVertexAttribArray<3> attribs; |
- size_t currentOffset = 0; |
int colorOffset = -1, texOffset = -1; |
+ set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset); |
- // 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()); |
- |
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"); |