当前位置: 首页>>代码示例>>C++>>正文


C++ GrDrawState::setVertexAttribs方法代码示例

本文整理汇总了C++中GrDrawState::setVertexAttribs方法的典型用法代码示例。如果您正苦于以下问题:C++ GrDrawState::setVertexAttribs方法的具体用法?C++ GrDrawState::setVertexAttribs怎么用?C++ GrDrawState::setVertexAttribs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GrDrawState的用法示例。


在下文中一共展示了GrDrawState::setVertexAttribs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onDrawPath

bool GrAndroidPathRenderer::onDrawPath(const SkPath& origPath,
                                       const SkStrokeRec& stroke,
                                       GrDrawTarget* target,
                                       bool antiAlias) {

    // generate verts using Android algorithm
    android::uirenderer::VertexBuffer vertices;
    android::uirenderer::PathRenderer::ConvexPathVertices(origPath, stroke, antiAlias, NULL,
                                                          &vertices);

    // set vertex attributes depending on anti-alias
    GrDrawState* drawState = target->drawState();
    if (antiAlias) {
        // position + coverage
        GrVertexAttrib attribs[] = {
            GrVertexAttrib(kVec2f_GrVertexAttribType, 0),
            GrVertexAttrib(kVec4ub_GrVertexAttribType, sizeof(GrPoint))
        };
        drawState->setVertexAttribs(attribs, SK_ARRAY_COUNT(attribs));
        drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
        drawState->setAttribIndex(GrDrawState::kCoverage_AttribIndex, 1);
        drawState->setAttribBindings(GrDrawState::kCoverage_AttribBindingsBit);
    } else {
        drawState->setDefaultVertexAttribs();
    }

    // allocate our vert buffer
    int vertCount = vertices.getSize();
    GrDrawTarget::AutoReleaseGeometry geo(target, vertCount, 0);
    if (!geo.succeeded()) {
        SkDebugf("Failed to get space for vertices!\n");
        return false;
    }

    // copy android verts to our vertex buffer
    if (antiAlias) {
        SkASSERT(sizeof(ColorVertex) == drawState->getVertexSize());
        ColorVertex* outVert = reinterpret_cast<ColorVertex*>(geo.vertices());
        android::uirenderer::AlphaVertex* inVert =
            reinterpret_cast<android::uirenderer::AlphaVertex*>(vertices.getBuffer());

        for (int i = 0; i < vertCount; ++i) {
            // copy vertex position
            outVert->pos.set(inVert->position[0], inVert->position[1]);
            // copy alpha
            int coverage = static_cast<int>(inVert->alpha * 0xff);
            outVert->color = GrColorPackRGBA(coverage, coverage, coverage, coverage);
            ++outVert;
            ++inVert;
        }
    } else {
       size_t vsize = drawState->getVertexSize();
       size_t copySize = vsize*vertCount;
       memcpy(geo.vertices(), vertices.getBuffer(), copySize);
    }

    // render it
    target->drawNonIndexed(kTriangleStrip_GrPrimitiveType, 0, vertCount);

    return true;
}
开发者ID:Ashu17,项目名称:blackberry,代码行数:61,代码来源:GrAndroidPathRenderer.cpp


注:本文中的GrDrawState::setVertexAttribs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。