Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: src/gpu/GrContext.cpp

Issue 14328009: Vertex Attrib configurations now handled as pointers vs. SkSTArrays (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Added "extern const" & removed comment Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/GrDrawState.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
« no previous file with comments | « src/gpu/GrAARectRenderer.cpp ('k') | src/gpu/GrDrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698