aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrAARectRenderer.cpp
diff options
context:
space:
mode:
authorGravatar jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-28 16:28:34 +0000
committerGravatar jvanverth@google.com <jvanverth@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-28 16:28:34 +0000
commitb8b705b1b983a2ee3a254bed4dd03f926101e4e7 (patch)
tree700a965273fff93e1cc821bfdbcc22028e138d46 /src/gpu/GrAARectRenderer.cpp
parent4aaaaeace7e617ddc473645756fb7c20790bc270 (diff)
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
Diffstat (limited to 'src/gpu/GrAARectRenderer.cpp')
-rw-r--r--src/gpu/GrAARectRenderer.cpp46
1 files changed, 35 insertions, 11 deletions
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index d23c4b4496..741b83d080 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -13,14 +13,15 @@ SK_DEFINE_INST_COUNT(GrAARectRenderer)
namespace {
-static GrVertexLayout aa_rect_layout(bool useCoverage) {
- GrVertexLayout layout = 0;
+static void aa_rect_attributes(bool useCoverage, GrAttribBindings* bindings,
+ GrDrawState::AttribIndex* index) {
if (useCoverage) {
- layout |= GrDrawState::kCoverage_VertexLayoutBit;
+ *bindings = GrDrawState::kCoverage_AttribBindingsBit;
+ *index = GrDrawState::kCoverage_AttribIndex;
} else {
- layout |= GrDrawState::kColor_VertexLayoutBit;
+ *bindings = GrDrawState::kColor_AttribBindingsBit;
+ *index = GrDrawState::kColor_AttribIndex;
}
- return layout;
}
static void set_inset_fan(GrPoint* pts, size_t stride,
@@ -29,6 +30,12 @@ static void set_inset_fan(GrPoint* pts, size_t stride,
r.fRight - dx, r.fBottom - dy, stride);
}
+// position + color/coverage
+static const GrVertexAttrib kVertexAttribs[] = {
+ GrVertexAttrib(kVec2f_GrVertexAttribType, 0),
+ GrVertexAttrib(kVec4ub_GrVertexAttribType, sizeof(GrPoint))
+};
+
};
void GrAARectRenderer::reset() {
@@ -125,8 +132,15 @@ void GrAARectRenderer::fillAARect(GrGpu* gpu,
GrDrawTarget* target,
const GrRect& devRect,
bool useVertexCoverage) {
- GrVertexLayout layout = aa_rect_layout(useVertexCoverage);
- target->drawState()->setVertexLayout(layout);
+ GrDrawState* drawState = target->drawState();
+
+ GrAttribBindings bindings;
+ GrDrawState::AttribIndex attribIndex;
+ aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex);
+ drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
+ drawState->setAttribBindings(bindings);
+ drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
+ drawState->setAttribIndex(attribIndex, 1);
GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0);
if (!geo.succeeded()) {
@@ -141,7 +155,8 @@ void GrAARectRenderer::fillAARect(GrGpu* gpu,
}
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
- size_t vsize = target->getDrawState().getVertexSize();
+ size_t vsize = drawState->getVertexSize();
+ GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
@@ -177,6 +192,8 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu,
const GrRect& devRect,
const GrVec& devStrokeSize,
bool useVertexCoverage) {
+ GrDrawState* drawState = target->drawState();
+
const SkScalar& dx = devStrokeSize.fX;
const SkScalar& dy = devStrokeSize.fY;
const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
@@ -195,8 +212,14 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu,
this->fillAARect(gpu, target, r, useVertexCoverage);
return;
}
- GrVertexLayout layout = aa_rect_layout(useVertexCoverage);
- target->drawState()->setVertexLayout(layout);
+
+ GrAttribBindings bindings;
+ GrDrawState::AttribIndex attribIndex;
+ aa_rect_attributes(useVertexCoverage, &bindings, &attribIndex);
+ drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
+ drawState->setAttribBindings(bindings);
+ drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
+ drawState->setAttribIndex(attribIndex, 1);
GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0);
if (!geo.succeeded()) {
@@ -210,7 +233,8 @@ void GrAARectRenderer::strokeAARect(GrGpu* gpu,
}
intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
- size_t vsize = target->getDrawState().getVertexSize();
+ size_t vsize = drawState->getVertexSize();
+ GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize);
// We create vertices for four nested rectangles. There are two ramps from 0 to full
// coverage, one on the exterior of the stroke and the other on the interior.