本文整理汇总了C++中GrMesh::initIndexed方法的典型用法代码示例。如果您正苦于以下问题:C++ GrMesh::initIndexed方法的具体用法?C++ GrMesh::initIndexed怎么用?C++ GrMesh::initIndexed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrMesh
的用法示例。
在下文中一共展示了GrMesh::initIndexed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void draw(GrVertexBatch::Target* target, const GrGeometryProcessor* gp, int vertexCount,
size_t vertexStride, void* vertices, int indexCount, uint16_t* indices) const {
if (vertexCount == 0 || indexCount == 0) {
return;
}
const GrBuffer* vertexBuffer;
GrMesh mesh;
int firstVertex;
void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex);
if (!verts) {
SkDebugf("Could not allocate vertices\n");
return;
}
memcpy(verts, vertices, vertexCount * vertexStride);
const GrBuffer* indexBuffer;
int firstIndex;
uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
if (!idxs) {
SkDebugf("Could not allocate indices\n");
return;
}
memcpy(idxs, indices, indexCount * sizeof(uint16_t));
mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex,
firstIndex, vertexCount, indexCount);
target->draw(gp, mesh);
}
示例2: onPrepareDraws
//.........这里部分代码省略.........
// We will use index buffers if we have multiple paths or one path with multiple contours
bool isIndexed = instanceCount > 1;
for (int i = 0; i < instanceCount; i++) {
const Geometry& args = fGeoData[i];
int contourCount;
maxVertices += GrPathUtils::worstCasePointCount(args.fPath, &contourCount,
args.fTolerance);
isIndexed = isIndexed || contourCount > 1;
}
if (maxVertices == 0 || maxVertices > ((int)SK_MaxU16 + 1)) {
//SkDebugf("Cannot render path (%d)\n", maxVertices);
return;
}
// determine primitiveType
int maxIndices = 0;
GrPrimitiveType primitiveType;
if (this->isHairline()) {
if (isIndexed) {
maxIndices = 2 * maxVertices;
primitiveType = kLines_GrPrimitiveType;
} else {
primitiveType = kLineStrip_GrPrimitiveType;
}
} else {
if (isIndexed) {
maxIndices = 3 * maxVertices;
primitiveType = kTriangles_GrPrimitiveType;
} else {
primitiveType = kTriangleFan_GrPrimitiveType;
}
}
// allocate vertex / index buffers
const GrBuffer* vertexBuffer;
int firstVertex;
void* verts = target->makeVertexSpace(vertexStride, maxVertices,
&vertexBuffer, &firstVertex);
if (!verts) {
SkDebugf("Could not allocate vertices\n");
return;
}
const GrBuffer* indexBuffer = nullptr;
int firstIndex = 0;
void* indices = nullptr;
if (isIndexed) {
indices = target->makeIndexSpace(maxIndices, &indexBuffer, &firstIndex);
if (!indices) {
SkDebugf("Could not allocate indices\n");
return;
}
}
// fill buffers
int vertexOffset = 0;
int indexOffset = 0;
for (int i = 0; i < instanceCount; i++) {
const Geometry& args = fGeoData[i];
int vertexCnt = 0;
int indexCnt = 0;
if (!this->createGeom(verts,
vertexOffset,
indices,
indexOffset,
&vertexCnt,
&indexCnt,
args.fPath,
args.fTolerance,
isIndexed)) {
return;
}
vertexOffset += vertexCnt;
indexOffset += indexCnt;
SkASSERT(vertexOffset <= maxVertices && indexOffset <= maxIndices);
}
GrMesh mesh;
if (isIndexed) {
mesh.initIndexed(primitiveType, vertexBuffer, indexBuffer, firstVertex, firstIndex,
vertexOffset, indexOffset);
} else {
mesh.init(primitiveType, vertexBuffer, firstVertex, vertexOffset);
}
target->draw(gp.get(), mesh);
// put back reserves
target->putBackIndices((size_t)(maxIndices - indexOffset));
target->putBackVertices((size_t)(maxVertices - vertexOffset), (size_t)vertexStride);
}
示例3: onPrepareDraws
void onPrepareDraws(Target* target) const override {
#ifndef SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS
if (this->linesOnly()) {
this->prepareLinesOnlyDraws(target);
return;
}
#endif
int instanceCount = fGeoData.count();
SkMatrix invert;
if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
SkDebugf("Could not invert viewmatrix\n");
return;
}
// Setup GrGeometryProcessor
sk_sp<GrGeometryProcessor> quadProcessor(
QuadEdgeEffect::Make(this->color(), invert, this->usesLocalCoords()));
// TODO generate all segments for all paths and use one vertex buffer
for (int i = 0; i < instanceCount; i++) {
const Geometry& args = fGeoData[i];
// We use the fact that SkPath::transform path does subdivision based on
// perspective. Otherwise, we apply the view matrix when copying to the
// segment representation.
const SkMatrix* viewMatrix = &args.fViewMatrix;
// We avoid initializing the path unless we have to
const SkPath* pathPtr = &args.fPath;
SkTLazy<SkPath> tmpPath;
if (viewMatrix->hasPerspective()) {
SkPath* tmpPathPtr = tmpPath.init(*pathPtr);
tmpPathPtr->setIsVolatile(true);
tmpPathPtr->transform(*viewMatrix);
viewMatrix = &SkMatrix::I();
pathPtr = tmpPathPtr;
}
int vertexCount;
int indexCount;
enum {
kPreallocSegmentCnt = 512 / sizeof(Segment),
kPreallocDrawCnt = 4,
};
SkSTArray<kPreallocSegmentCnt, Segment, true> segments;
SkPoint fanPt;
if (!get_segments(*pathPtr, *viewMatrix, &segments, &fanPt, &vertexCount,
&indexCount)) {
continue;
}
const GrBuffer* vertexBuffer;
int firstVertex;
size_t vertexStride = quadProcessor->getVertexStride();
QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertexSpace(
vertexStride, vertexCount, &vertexBuffer, &firstVertex));
if (!verts) {
SkDebugf("Could not allocate vertices\n");
return;
}
const GrBuffer* indexBuffer;
int firstIndex;
uint16_t *idxs = target->makeIndexSpace(indexCount, &indexBuffer, &firstIndex);
if (!idxs) {
SkDebugf("Could not allocate indices\n");
return;
}
SkSTArray<kPreallocDrawCnt, Draw, true> draws;
create_vertices(segments, fanPt, &draws, verts, idxs);
GrMesh mesh;
for (int j = 0; j < draws.count(); ++j) {
const Draw& draw = draws[j];
mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, firstIndex, draw.fVertexCnt, draw.fIndexCnt);
target->draw(quadProcessor.get(), mesh);
firstVertex += draw.fVertexCnt;
firstIndex += draw.fIndexCnt;
}
}
}
示例4: prepareLinesOnlyDraws
void prepareLinesOnlyDraws(Target* target) const {
bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
// Setup GrGeometryProcessor
sk_sp<GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage,
this->viewMatrix(),
this->usesLocalCoords(),
this->coverageIgnored()));
if (!gp) {
SkDebugf("Could not create GrGeometryProcessor\n");
return;
}
size_t vertexStride = gp->getVertexStride();
SkASSERT(canTweakAlphaForCoverage ?
vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
GrAAConvexTessellator tess;
int instanceCount = fGeoData.count();
for (int i = 0; i < instanceCount; i++) {
tess.rewind();
const Geometry& args = fGeoData[i];
if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
continue;
}
const GrBuffer* vertexBuffer;
int firstVertex;
void* verts = target->makeVertexSpace(vertexStride, tess.numPts(), &vertexBuffer,
&firstVertex);
if (!verts) {
SkDebugf("Could not allocate vertices\n");
return;
}
const GrBuffer* indexBuffer;
int firstIndex;
uint16_t* idxs = target->makeIndexSpace(tess.numIndices(), &indexBuffer, &firstIndex);
if (!idxs) {
SkDebugf("Could not allocate indices\n");
return;
}
extract_verts(tess, verts, vertexStride, args.fColor, idxs, canTweakAlphaForCoverage);
GrMesh mesh;
mesh.initIndexed(kTriangles_GrPrimitiveType,
vertexBuffer, indexBuffer,
firstVertex, firstIndex,
tess.numPts(), tess.numIndices());
target->draw(gp.get(), mesh);
}
}