Add new vertex attribute array specification.
This changes the old method of setting vertex layout to a new one where we
specify vertex attribute data separately from attribute bindings (i.e. program
functionality). Attribute data is now set up via an array of generic attribute
types and offsets, and this is mapped to the old program functionality by
setting specific attribute indices. This allows us to create more general
inputs to shaders.
git-svn-id: http://skia.googlecode.com/svn/trunk@7899 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index e599fc9..e77bf93 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -92,8 +92,6 @@
fVertices = NULL;
fMaxVertices = 0;
-
- fVertexLayout = GrDrawState::StageTexCoordVertexLayoutBit(kGlyphMaskStage);
}
GrTextContext::~GrTextContext() {
@@ -189,13 +187,20 @@
}
if (NULL == fVertices) {
- // If we need to reserve vertices allow the draw target to suggest
+ // position + texture coord
+ static const GrVertexAttrib kVertexAttribs[] = {
+ GrVertexAttrib(kVec2f_GrVertexAttribType, 0),
+ GrVertexAttrib(kVec2f_GrVertexAttribType, sizeof(GrPoint))
+ };
+ static const GrAttribBindings kAttribBindings = GrDrawState::ExplicitTexCoordAttribBindingsBit(kGlyphMaskStage);
+
+ // If we need to reserve vertices allow the draw target to suggest
// a number of verts to reserve and whether to perform a flush.
fMaxVertices = kMinRequestedVerts;
bool flush = false;
fDrawTarget = fContext->getTextTarget(fPaint);
if (NULL != fDrawTarget) {
- fDrawTarget->drawState()->setVertexLayout(fVertexLayout);
+ fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
flush = fDrawTarget->geometryHints(&fMaxVertices, NULL);
}
if (flush) {
@@ -203,8 +208,11 @@
fContext->flush();
// flushGlyphs() will reset fDrawTarget to NULL.
fDrawTarget = fContext->getTextTarget(fPaint);
- fDrawTarget->drawState()->setVertexLayout(fVertexLayout);
+ fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
}
+ fDrawTarget->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
+ fDrawTarget->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
+ fDrawTarget->drawState()->setAttribBindings(kAttribBindings);
fMaxVertices = kDefaultRequestedVerts;
// ignore return, no point in flushing again.
fDrawTarget->geometryHints(&fMaxVertices, NULL);
@@ -222,6 +230,7 @@
GrTCast<void**>(&fVertices),
NULL);
GrAlwaysAssert(success);
+ GrAssert(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize());
}
GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX);