diff options
author | 2013-02-28 16:28:34 +0000 | |
---|---|---|
committer | 2013-02-28 16:28:34 +0000 | |
commit | b8b705b1b983a2ee3a254bed4dd03f926101e4e7 (patch) | |
tree | 700a965273fff93e1cc821bfdbcc22028e138d46 /src/gpu/GrDrawTarget.cpp | |
parent | 4aaaaeace7e617ddc473645756fb7c20790bc270 (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/GrDrawTarget.cpp')
-rw-r--r-- | src/gpu/GrDrawTarget.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index 2c2d949224..dab2965c6b 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -530,11 +530,19 @@ void GrDrawTarget::drawRect(const GrRect& rect, const GrRect* srcRect, const SkMatrix* srcMatrix, int stage) { - GrVertexLayout layout = 0; + GrAttribBindings bindings = 0; uint32_t explicitCoordMask = 0; + // position + (optional) texture coord + static const GrVertexAttrib kAttribs[] = { + GrVertexAttrib(kVec2f_GrVertexAttribType, 0), + GrVertexAttrib(kVec2f_GrVertexAttribType, sizeof(GrPoint)) + }; + int attribCount = 1; if (NULL != srcRect) { - layout |= GrDrawState::StageTexCoordVertexLayoutBit(stage); + bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage); + attribCount = 2; + this->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1); explicitCoordMask = (1 << stage); } @@ -543,30 +551,26 @@ void GrDrawTarget::drawRect(const GrRect& rect, avmr.set(this->drawState(), *matrix, explicitCoordMask); } - this->drawState()->setVertexLayout(layout); + this->drawState()->setVertexAttribs(kAttribs, attribCount); + this->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0); + this->drawState()->setAttribBindings(bindings); AutoReleaseGeometry geo(this, 4, 0); if (!geo.succeeded()) { GrPrintf("Failed to get space for vertices!\n"); return; } - int stageOffsets[GrDrawState::kNumStages]; - int vsize = GrDrawState::VertexSizeAndOffsetsByStage(layout, stageOffsets, NULL, NULL, NULL); + size_t vsize = this->drawState()->getVertexSize(); geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize); - - for (int i = 0; i < GrDrawState::kNumStages; ++i) { - if (explicitCoordMask & (1 << i)) { - GrAssert(0 != stageOffsets[i]); - GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + - stageOffsets[i]); - coords->setRectFan(srcRect->fLeft, srcRect->fTop, - srcRect->fRight, srcRect->fBottom, - vsize); - if (NULL != srcMatrix) { - srcMatrix->mapPointsWithStride(coords, vsize, 4); - } - } else { - GrAssert(0 == stageOffsets[i]); + if (NULL != srcRect) { + GrAssert(attribCount == 2); + GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + + kAttribs[1].fOffset); + coords->setRectFan(srcRect->fLeft, srcRect->fTop, + srcRect->fRight, srcRect->fBottom, + vsize); + if (NULL != srcMatrix) { + srcMatrix->mapPointsWithStride(coords, vsize, 4); } } |